use Method::Signatures::Simple;
use Carp::Clan qw/^DBIx::Class/;
use aliased 'DBIx::Class::ResultSource::Table';
+use aliased 'DBIx::Class::ResultClass::HashRefInflator';
use namespace::autoclean;
# how this works:
my $new = $class->next::method(@args);
my $rc = $new->result_class;
if (my $meth = $rc->can('result_source_instance')) {
- $new->parent_source($rc->$meth);
- }
- if ($new->schema) {
- $new->_attach_additional_sources;
+ my $source = $rc->$meth;
+ if ($source->result_class ne $new->result_class
+ && $new->result_class->isa($source->result_class)) {
+ $new->parent_source($source);
+ }
}
return $new;
}
+method schema (@args) {
+ my $ret = $self->next::method(@args);
+ if (@args) {
+ $self->_attach_additional_sources;
+ }
+ return $ret;
+}
+
method _attach_additional_sources () {
my $raw_name = $self->_raw_source_name;
my $schema = $self->schema;
foreach my $pri ($self->primary_columns) {
my %info = %{$self->column_info($pri)};
delete @info{qw(is_auto_increment sequence auto_nextval)};
- $self->add_column($pri => \%info);
+ $table->add_column($pri => \%info);
$join{"foreign.${pri}"} = "self.${pri}";
}
- $self->add_relationship('parent', $parent->source_name, \%join);
+ $table->add_relationship('parent', $parent->source_name, \%join);
}
$table->set_primary_key($self->primary_columns);
$schema->register_source($raw_name => $table);
--- /dev/null
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More qw(no_plan);
+use Data::Dumper; $Data::Dumper::Indent = 1;
+
+BEGIN { use_ok 'MTITest'; }
+
+warn MTITest->sources;
+
+my $raw_foo = MTITest->source('Raw::Foo');
+
+is_deeply(
+ [ $raw_foo->columns ],
+ [ qw(id a) ],
+ 'Columns for raw foo ok'
+);
+
+warn Dumper $raw_foo->_columns;
--- /dev/null
+package MTITest::Result::Bar;
+
+use strict;
+use warnings;
+use parent qw(MTITest::Result::Foo);
+
+__PACKAGE__->table('bar');
+
+__PACKAGE__->add_columns(
+ b => { data_type => 'integer' }
+);
+
+1;
--- /dev/null
+package MTITest::Result::Foo;
+
+use strict;
+use warnings;
+use parent qw(DBIx::Class::Core);
+use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance';
+
+__PACKAGE__->table_class(MultipleTableInheritance);
+
+__PACKAGE__->table('foo');
+
+__PACKAGE__->add_columns(
+ id => { data_type => 'integer', is_auto_increment => 1 },
+ a => { data_type => 'text' }
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;