From: David Kamholz Date: Sun, 12 Feb 2006 15:56:01 +0000 (+0000) Subject: - allow specification of related columns via cols attr when X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f5541c370b3ed1aeb4a2ef3bc05b6ea036e874f1;p=dbsrgits%2FDBIx-Class-Historic.git - allow specification of related columns via cols attr when primary keys of the related table are not fetched - updated manifest --- diff --git a/MANIFEST b/MANIFEST index 5f75b92..ff271fb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -64,17 +64,29 @@ lib/DBIx/Class/ResultSourceProxy.pm lib/DBIx/Class/ResultSourceProxy/Table.pm lib/DBIx/Class/Row.pm lib/DBIx/Class/Schema.pm -lib/DBIx/Class/Serialize.pm +lib/DBIx/Class/Serialize/Storable.pm lib/DBIx/Class/Storage/DBI.pm lib/DBIx/Class/Storage/DBI/Cursor.pm +lib/DBIx/Class/Storage/DBI/DB2.pm +lib/DBIx/Class/Storage/DBI/MSSQL.pm +lib/DBIx/Class/Storage/DBI/mysql.pm +lib/DBIx/Class/Storage/DBI/Oracle.pm +lib/DBIx/Class/Storage/DBI/Pg.pm +lib/DBIx/Class/Storage/DBI/SQLite.pm lib/DBIx/Class/Test/SQLite.pm lib/DBIx/Class/UUIDColumns.pm +lib/DBIx/Class/UUIDMaker.pm +lib/DBIx/Class/UUIDMaker/APR/UUID.pm +lib/DBIx/Class/UUIDMaker/Data/Uniqid.pm +lib/DBIx/Class/UUIDMaker/Data/UUID.pm +lib/DBIx/Class/UUIDMaker/UUID.pm +lib/DBIx/Class/UUIDMaker/Win32/Guidgen.pm +lib/DBIx/Class/UUIDMaker/Win32API/GUID.pm lib/DBIx/Class/Validation.pm lib/SQL/Translator/Parser/DBIx/Class.pm lib/SQL/Translator/Producer/DBIx/Class/File.pm Makefile.PL MANIFEST This list of files -META.yml README t/02pod.t t/03podcoverage.t.disabled @@ -96,12 +108,15 @@ t/basicrels/10auto.t t/basicrels/11mysql.t t/basicrels/12pg.t t/basicrels/13oracle.t +t/basicrels/145db2.t t/basicrels/14mssql.t t/basicrels/15limit.t t/basicrels/16joins.t t/basicrels/17join_count.t t/basicrels/18self_referencial.t t/basicrels/19uuid.t +t/basicrels/20unique.t +t/basicrels/21serialize.t t/cdbi-sweet-t/08pager.t t/cdbi-t/01-columns.t t/cdbi-t/02-Film.t @@ -133,6 +148,7 @@ t/helperrels/10auto.t t/helperrels/11mysql.t t/helperrels/12pg.t t/helperrels/13oracle.t +t/helperrels/145db2.t t/helperrels/14mssql.t t/helperrels/15limit.t t/helperrels/16joins.t @@ -140,6 +156,7 @@ t/helperrels/17join_count.t t/helperrels/18self_referencial.t t/helperrels/19uuid.t t/helperrels/20unique.t +t/helperrels/21serialize.t t/lib/DBICTest.pm t/lib/DBICTest/BasicRels.pm t/lib/DBICTest/Extra.pm @@ -178,6 +195,7 @@ t/run/10auto.tl t/run/11mysql.tl t/run/12pg.tl t/run/13oracle.tl +t/run/145db2.tl t/run/14mssql.tl t/run/15limit.tl t/run/16joins.tl @@ -185,6 +203,7 @@ t/run/17join_count.tl t/run/18self_referencial.tl t/run/19uuid.tl t/run/20unique.tl +t/run/21serialize.tl t/testlib/Actor.pm t/testlib/ActorAlias.pm t/testlib/Binary.pm @@ -203,3 +222,4 @@ t/testlib/MyStarLinkMCPK.pm t/testlib/Order.pm t/testlib/OtherFilm.pm t/testlib/PgBase.pm +META.yml 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');