X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frun%2F16joins.tl;h=3ea71f1898e1b0005242f565ec993e6b3c1326f7;hb=c5b7d79941cd6942aeec1e81e1d4f7f9ad7eb62f;hp=0f59ab74da891d2742fe9080632f87368be9dadf;hpb=b3e8ac9b6c2b4b611b3f34f4024f64f352d8e9fa;p=dbsrgits%2FDBIx-Class.git diff --git a/t/run/16joins.tl b/t/run/16joins.tl index 0f59ab7..3ea71f1 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 => 27 ); + : ( tests => 33 ); } # test the abstract join => SQL generator @@ -151,8 +151,8 @@ is( $tag->cd->artist->name, 'Caterwauler McCrae', 'step 2 ok for nested prefetch # count the SELECTs DBI->trace(0, undef); -my $selects = 0; -my $trace = IO::File->new('t/var/dbic.trace', '<') +$selects = 0; +$trace = IO::File->new('t/var/dbic.trace', '<') or die "Unable to read trace file"; while (<$trace>) { $selects++ if /SELECT(?!.*WHERE 1=0.*)/; @@ -161,6 +161,26 @@ $trace->close; unlink 't/var/dbic.trace'; is($selects, 1, 'nested prefetch ran exactly 1 select statement (excluding column_info)'); +# start test for prefetch on find SELECT count +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' }); + +is($cd->{_inflated_column}{artist}->name, 'Caterwauler McCrae', 'artist prefetched correctly on find'); + +# count the SELECTs +DBI->trace(0, undef); +$selects = 0; +$trace = IO::File->new('t/var/dbic.trace', '<') + or die "Unable to read trace file"; +while (<$trace>) { + $selects++ if /SELECT(?!.*WHERE 1=0.*)/; +} +$trace->close; +unlink 't/var/dbic.trace'; +is($selects, 1, 'find with prefetch ran exactly 1 select statement (excluding column_info)'); + $rs = $schema->resultset('Tag')->search( {}, { @@ -188,6 +208,23 @@ my @artists = $schema->resultset("Artist")->search({ 'tags.tag' => 'Shiny' }, cmp_ok( @artists, '==', 2, "two-join search ok" ); +$rs = $schema->resultset("CD")->search( + {}, + { group_by => [qw/ title me.cdid /] } +); + +cmp_ok( $rs->count, '==', 5, "count() ok after group_by on main pk" ); + +cmp_ok( scalar $rs->all, '==', 5, "all() returns same count as count() after group_by on main pk" ); + +$rs = $schema->resultset("CD")->search( + {}, + { join => [qw/ artist /], group_by => [qw/ artist.name /] } +); + +cmp_ok( $rs->count, '==', 3, "count() ok after group_by on related column" ); + +cmp_ok( scalar $rs->all, '==', 3, "all() returns same count as count() after group_by on related column" ); } 1;