Standardize hobbs' email address
[dbsrgits/DBIx-Class.git] / t / count / joined.t
CommitLineData
21bd38f8 1use strict;
2use warnings;
3
4use Test::More;
5
6use lib qw(t/lib);
7
8use DBICTest;
9
b9ecae39 10plan tests => 7;
21bd38f8 11
12my $schema = DBICTest->init_schema();
13
a258ee5d 14my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } });
15cmp_ok($cds->count, '>', 1, "extra joins explode entity count");
16
17is (
18 $cds->search({}, { prefetch => 'cd_to_producer' })->count,
19 1,
20 "Count correct with extra joins collapsed by prefetch"
21);
22
23is (
24 $cds->search({}, { distinct => 1 })->count,
25 1,
26 "Count correct with requested distinct collapse of main table"
27);
28
b683f352 29# JOIN and LEFT JOIN issues mean that we've seen problems where counted rows and fetched rows are sometimes 1 higher than they should
30# be in the related resultset.
d3cceebf 31my $artist=$schema->resultset('Artist')->create({name => 'xxx'});
b683f352 32is($artist->related_resultset('cds')->count(), 0, "No CDs found for a shiny new artist");
33is(scalar($artist->related_resultset('cds')->all()), 0, "No CDs fetched for a shiny new artist");
34
d3cceebf 35my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id});
b683f352 36is($artist_rs->related_resultset('cds')->count(), 0, "No CDs counted for a shiny new artist using a resultset search");
37is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched for a shiny new artist using a resultset search");