From: Matt S Trout Date: Fri, 23 Sep 2005 16:48:37 +0000 (+0000) Subject: Fixed prefetch bug and added a test for it (spotted by Purge) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dd417d064c7b003f1a6ba924045c79045ce0b515;p=dbsrgits%2FDBIx-Class-Historic.git Fixed prefetch bug and added a test for it (spotted by Purge) --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index db8d56d..3297235 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -86,9 +86,10 @@ sub _construct_object { $new = $self->{class}->_row_to_object(\@cols, \@main); PRE: foreach my $pre (@{$self->{attrs}{prefetch}}) { my $rel_obj = $self->{class}->_relationships->{$pre}; - my @pre_cols = $rel_obj->{class}->columns; + my $pre_class = $self->{class}->resolve_class($rel_obj->{class}); + my @pre_cols = $pre_class->_select_columns; my @vals = splice(@row, 0, scalar @pre_cols); - my $fetched = $rel_obj->{class}->_row_to_object(\@pre_cols, \@vals); + my $fetched = $pre_class->_row_to_object(\@pre_cols, \@vals); $self->{class}->throw("No accessor for prefetched $pre") unless defined $rel_obj->{attrs}{accessor}; if ($rel_obj->{attrs}{accessor} eq 'single') { diff --git a/t/run/16joins.tl b/t/run/16joins.tl index 89d9947..3f7e596 100644 --- a/t/run/16joins.tl +++ b/t/run/16joins.tl @@ -6,7 +6,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 21 ); + : ( tests => 22 ); } # test the abstract join => SQL generator @@ -119,6 +119,8 @@ ok(!exists $cd[0]->{_relationship_data}{liner_notes}, 'No prefetch for NULL LEFT is($cd[1]->{_relationship_data}{liner_notes}->notes, 'Buy Whiskey!', 'Prefetch for present LEFT JOIN'); +is(ref $cd[1]->liner_notes, 'DBICTest::LinerNotes', 'Prefetch returns correct class'); + is($cd[2]->{_inflated_column}{artist}->name, 'Caterwauler McCrae', 'Prefetch on parent object ok'); # count the SELECTs