use warnings;
use parent qw(DBIx::Class::ResultSource::View);
use Method::Signatures::Simple;
+use Carp::Always;
use Carp::Clan qw/^DBIx::Class/;
use aliased 'DBIx::Class::ResultSource::Table';
use aliased 'DBIx::Class::ResultClass::HashRefInflator';
#
# On construction, we hook $self->result_class->result_source_instance
# if present to get the superclass' source object
-#
+#
# When attached to a schema, we need to add sources to that schema with
# appropriate relationships for the foreign keys so the concrete tables
# get generated
method _source_by_name ($name) {
my $schema = $self->schema;
- my ($source) =
+ my ($source) =
grep { $_->name eq $name }
map $schema->source($_), $schema->sources;
confess "Couldn't find attached source for parent $name - did you use load_classes? This module is only compatible with load_namespaces"
@{$self->additional_parents||[]}
]);
}
- use Devel::Dwarn; use 5.012; say Dwarn $ret;
return $ret;
}
my $parent;
if ($self->parent_source) {
my $parent_name = $self->parent_source->name;
- ($parent) =
+ ($parent) =
grep { $_->name eq $parent_name }
map $schema->source($_), $schema->sources;
confess "Couldn't find attached source for parent $parent_name - did you use load_classes? This module is only compatible with load_namespaces"
$self->columns
);
$table->set_primary_key($self->primary_columns);
-
+
## Attempting to re-add sequence here -- AKB
- for my $pk ( $self->primary_columns ) {
- if ($parent) {
-
-#use 5.012; use Devel::Dwarn; say Dwarn $schema->source($table->_relationships->{parent}->{class}) if $table->_relationships->{parent}->{class};
- $table->columns_info->{$pk}->{sequence} =
- $self->set_sequence(
- $schema->source( $table->_relationships->{parent}->{class} )->name,
- $self->primary_columns )
- if $table->columns_info->{$pk}->{originally_defined_in} ne $self->name
- && $table->_relationships->{parent}->{class};
- }
- }
+ #for my $pk ( $self->primary_columns ) {
+ #if ($parent) {
+
+##use 5.012; use Devel::Dwarn; say Dwarn $schema->source($table->_relationships->{parent}->{class}) if $table->_relationships->{parent}->{class};
+ #$table->columns_info->{$pk}->{sequence} =
+ #$self->set_sequence(
+ #$schema->source( $table->_relationships->{parent}->{class} )->name,
+ #$self->primary_columns )
+ #if $table->columns_info->{$pk}->{originally_defined_in} ne $self->name
+ #&& $table->_relationships->{parent}->{class};
+ #}
+ #}
# we need to copy our rels to the raw object as well
# note that ->add_relationship on a source object doesn't create an
my $f_source_name = $f_source->${\
($one_of_us ? 'raw_source_name' : 'source_name')
};
-
+
$table->add_relationship(
'_'.$rel, $f_source_name, @{$rel_info}{qw(cond attrs)}
);
=head1 NAME
DBIx::Class::ResultSource::MultipleTableInheritance
-Use multiple tables to define your classes
+Use multiple tables to define your classes
=head1 NOTICE
1;
}
-
+
...
my $schema = Cafe->connect($dsn,$user,$pass);
have this schema:
# Conceptual domain model
-
+
class User {
has id,
has name,
"name" text not null,
"password" text not null
);
-
+
create table "investor" (
"id" integer not null references user("id"),
"dollars" integer
So that investor's PK is just an FK to the user. We can clearly see the class
hierarchy here, in which investor is a subclass of user. In DBIx::Class
applications, this second strategy looks like:
-
+
my $user_rs = $schema->resultset('User');
my $new_user = $user_rs->create(
name => $args->{name},
password => $args->{password},
dollars => $args->{dollars},
);
-
+
And have it Just Work? The user...
{
print STDERR map { "$_\n" } MyApp::Schema->sources;
- # Coffee
+ # Coffee
# Beverage
# Liquid
# Sumatra