From: David Kamholz Date: Sun, 12 Feb 2006 19:35:58 +0000 (+0000) Subject: put last change in trunk X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d20bb28ea937ea4f890aa463452414a764bc24ef;p=dbsrgits%2FDBIx-Class-Historic.git put last change in trunk --- diff --git a/Changes b/Changes index 922ef98..183046b 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - allow specification of related columns via cols attr when primary + keys of the related table are not fetched - add horrific fix to make Oracle's retarded limit syntax work 0.05003 2006-02-08 17:50:20 diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 3606235..bf4a526 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -278,17 +278,16 @@ sub inflate_result { PRE: foreach my $pre (keys %{$prefetch||{}}) { my $pre_source = $source->related_source($pre); $class->throw_exception("Can't prefetch non-existant relationship ${pre}") unless $pre_source; - my $fetched = $pre_source->result_class->inflate_result( - $pre_source, @{$prefetch->{$pre}}); + my $fetched; + unless ($pre_source->primary_columns == grep { exists $prefetch->{$pre}[0]{$_} + and !defined $prefetch->{$pre}[0]{$_} } $pre_source->primary_columns) + { + $fetched = $pre_source->result_class->inflate_result( + $pre_source, @{$prefetch->{$pre}}); + } my $accessor = $source->relationship_info($pre)->{attrs}{accessor}; $class->throw_exception("No accessor for prefetched $pre") unless defined $accessor; - PRIMARY: foreach my $pri ($pre_source->primary_columns) { - unless (defined $fetched->get_column($pri)) { - undef $fetched; - last PRIMARY; - } - } if ($accessor eq 'single') { $new->{_relationship_data}{$pre} = $fetched; } elsif ($accessor eq 'filter') { diff --git a/t/run/16joins.tl b/t/run/16joins.tl index 5307067..a3c9383 100644 --- a/t/run/16joins.tl +++ b/t/run/16joins.tl @@ -7,7 +7,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 40 ); + : ( tests => 41 ); } # test the abstract join => SQL generator @@ -132,6 +132,15 @@ $trace->close; unlink 't/var/dbic.trace'; is($selects, 1, 'prefetch ran only 1 select statement'); +# test for partial prefetch via cols attr +my $cd = $schema->resultset('CD')->find(1, + { + cols => [qw/title artist.name/], + join => 'artist' + } +); +ok(eval { $cd->artist->name eq 'Caterwauler McCrae' }, 'single related column prefetched'); + # start test for nested prefetch SELECT count unlink 't/var/dbic.trace' if -e 't/var/dbic.trace'; DBI->trace(1, 't/var/dbic.trace'); @@ -165,7 +174,7 @@ is($selects, 1, 'nested prefetch ran exactly 1 select statement (excluding colum unlink 't/var/dbic.trace' if -e 't/var/dbic.trace'; DBI->trace(1, 't/var/dbic.trace'); -my $cd = $schema->resultset('CD')->find(1, { prefetch => 'artist' }); +$cd = $schema->resultset('CD')->find(1, { prefetch => 'artist' }); is($cd->{_inflated_column}{artist}->name, 'Caterwauler McCrae', 'artist prefetched correctly on find');