X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcount%2Fjoined.t;h=352eef9de194b319daf070a8e3b755ab58c6c79f;hb=fa19e5d684ce8181f2fa2e0cd79bed14de889650;hp=139f9cd14faadc3f54813ebd4a113136e166c5ab;hpb=6100596b36d03566ade6a98ed4c375d317ff83f8;p=dbsrgits%2FDBIx-Class.git diff --git a/t/count/joined.t b/t/count/joined.t index 139f9cd..352eef9 100644 --- a/t/count/joined.t +++ b/t/count/joined.t @@ -7,11 +7,31 @@ use lib qw(t/lib); use DBICTest; -plan tests => 1; +plan tests => 7; my $schema = DBICTest->init_schema(); -{ - my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } }); - is($cds->count, 1, "extra joins do not explode single entity count"); -} +my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } }); +cmp_ok($cds->count, '>', 1, "extra joins explode entity count"); + +is ( + $cds->search({}, { prefetch => 'cd_to_producer' })->count, + 1, + "Count correct with extra joins collapsed by prefetch" +); + +is ( + $cds->search({}, { distinct => 1 })->count, + 1, + "Count correct with requested distinct collapse of main table" +); + +# JOIN and LEFT JOIN issues mean that we've seen problems where counted rows and fetched rows are sometimes 1 higher than they should +# be in the related resultset. +my $artist=$schema->resultset('Artist')->create({name => 'xxx'}); +is($artist->related_resultset('cds')->count(), 0, "No CDs found for a shiny new artist"); +is(scalar($artist->related_resultset('cds')->all()), 0, "No CDs fetched for a shiny new artist"); + +my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id}); +is($artist_rs->related_resultset('cds')->count(), 0, "No CDs counted for a shiny new artist using a resultset search"); +is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched for a shiny new artist using a resultset search");