From: Matt S Trout Date: Tue, 18 Aug 2009 04:45:46 +0000 (+0100) Subject: apparently working additional parent support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b229aa66925691045fa50f2ff4ad3564a5a3358;p=dbsrgits%2FDBIx-Class-ResultSource-MultipleTableInheritance.git apparently working additional parent support --- diff --git a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm index 0a45aa8..d385727 100644 --- a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm +++ b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm @@ -67,19 +67,27 @@ method add_additional_parent ($source) { } } +method _source_by_name ($name) { + my $schema = $self->schema; + 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" + unless $source; + return $source; +} + method schema (@args) { my $ret = $self->next::method(@args); if (@args) { if ($self->parent_source) { - my $schema = $self->schema; my $parent_name = $self->parent_source->name; - my ($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" - unless $parent; - $self->parent_source($parent); # so our parent is the one in this schema + $self->parent_source($self->_source_by_name($parent_name)); } + $self->additional_parents([ + map { $self->_source_by_name($_->name) } + @{$self->additional_parents||[]} + ]); } return $ret; } diff --git a/t/01load.t b/t/01load.t index e5bebd3..dd10a1b 100644 --- a/t/01load.t +++ b/t/01load.t @@ -6,8 +6,6 @@ use Data::Dumper; $Data::Dumper::Indent = 1; BEGIN { use_ok 'MTITest'; } -warn MTITest->sources; - my $raw_foo = MTITest->source('Raw::Foo'); is_deeply( diff --git a/t/02view_def.t b/t/02view_def.t index 1d82d4e..e4f888f 100644 --- a/t/02view_def.t +++ b/t/02view_def.t @@ -1,6 +1,7 @@ use strict; use warnings; use lib 't/lib'; +use File::Temp; use Test::More qw(no_plan); use Test::Exception; use Data::Dumper; $Data::Dumper::Indent = 1; @@ -12,4 +13,10 @@ dies_ok { MTITest->source('Foo')->view_definition } my $schema = MTITest->connect('dbi:SQLite::memory:'); -warn $schema->source($_)->view_definition for qw(Foo Bar); +my $dir = "t/sql"; # tempdir(CLEANUP => 0); + +$schema->create_ddl_dir([ 'PostgreSQL' ], 0.1, $dir); + +#warn $schema->source($_)->view_definition for qw(Foo Bar); +#use Data::Dumper; $Data::Dumper::Indent = 1; +#warn Dumper($schema->source($_)) for qw(Foo Bar); diff --git a/t/lib/MTITest/Result/Bar.pm b/t/lib/MTITest/Result/Bar.pm index c47448f..b02325c 100644 --- a/t/lib/MTITest/Result/Bar.pm +++ b/t/lib/MTITest/Result/Bar.pm @@ -4,8 +4,14 @@ use strict; use warnings; use parent qw(MTITest::Result::Foo); +require MTITest::Result::Mixin; + __PACKAGE__->table('bar'); +__PACKAGE__->result_source_instance->add_additional_parent( + MTITest::Result::Mixin->result_source_instance +); + __PACKAGE__->add_columns( b => { data_type => 'integer' } ); diff --git a/t/lib/MTITest/Result/Foo.pm b/t/lib/MTITest/Result/Foo.pm index 450271d..d8b8e1b 100644 --- a/t/lib/MTITest/Result/Foo.pm +++ b/t/lib/MTITest/Result/Foo.pm @@ -11,7 +11,7 @@ __PACKAGE__->table('foo'); __PACKAGE__->add_columns( id => { data_type => 'integer', is_auto_increment => 1 }, - a => { data_type => 'integer' } + a => { data_type => 'integer', is_nullable => 1 } ); __PACKAGE__->set_primary_key('id'); diff --git a/t/lib/MTITest/Result/Mixin.pm b/t/lib/MTITest/Result/Mixin.pm new file mode 100644 index 0000000..e6c1124 --- /dev/null +++ b/t/lib/MTITest/Result/Mixin.pm @@ -0,0 +1,18 @@ +package MTITest::Result::Mixin; + +use strict; +use warnings; +use parent qw(DBIx::Class::Core); + +__PACKAGE__->table('mixin'); + +__PACKAGE__->add_columns( + id => { + data_type => 'integer', is_auto_increment => 1, sequence => 'foo_id_seq' + }, + words => { data_type => 'text' } +); + +__PACKAGE__->set_primary_key('id'); + +1;