From: Matt S Trout Date: Mon, 17 Aug 2009 19:38:42 +0000 (+0100) Subject: move additional source attach X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c73d582be5fced9cdcfbf31808ff8ec62aca66ec;p=dbsrgits%2FDBIx-Class-ResultSource-MultipleTableInheritance.git move additional source attach --- diff --git a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm index 2606b95..dcb40a1 100644 --- a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm +++ b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm @@ -44,12 +44,21 @@ method new ($class: @args) { method schema (@args) { my $ret = $self->next::method(@args); if (@args) { - $self->_attach_additional_sources; + 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 + } } return $ret; } -method _attach_additional_sources () { +method attach_additional_sources () { my $raw_name = $self->raw_source_name; my $schema = $self->schema; diff --git a/t/lib/MTITest.pm b/t/lib/MTITest.pm index 91471fd..3b1593a 100644 --- a/t/lib/MTITest.pm +++ b/t/lib/MTITest.pm @@ -3,7 +3,12 @@ package MTITest; use strict; use warnings; use parent qw(DBIx::Class::Schema); +use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance' => 'MTIView'; -__PACKAGE__->load_namespaces; +for my $p (__PACKAGE__) { + $p->load_namespaces; + $_->attach_additional_sources + for grep $_->isa(MTIView), map $p->source($_), $p->sources; +} 1;