Deprecate _build_unique_cond, move its guts to ::ResultSource where it belongs
[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
21bd38f8 10my $schema = DBICTest->init_schema();
11
a258ee5d 12my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } });
13cmp_ok($cds->count, '>', 1, "extra joins explode entity count");
14
6aa93928 15for my $arg (
16 [ 'prefetch-collapsed has_many' => { prefetch => 'cd_to_producer' } ],
17 [ 'distict-collapsed result' => { distinct => 1 } ],
18 [ 'explicit collapse request' => { collapse => 1 } ],
19) {
20 for my $hri (0,1) {
21 my $diag = $arg->[0] . ($hri ? ' with HRI' : '');
22
23 my $rs = $cds->search({}, {
24 %{$arg->[1]},
25 $hri ? ( result_class => 'DBIx::Class::ResultClass::HashRefInflator' ) : (),
26 });
27
28 is
29 $rs->count,
30 1,
31 "Count correct on $diag",
32 ;
33
34 is
35 scalar $rs->all,
36 1,
37 "Amount of constructed objects matches count on $diag",
38 ;
39 }
40}
a258ee5d 41
b683f352 42# JOIN and LEFT JOIN issues mean that we've seen problems where counted rows and fetched rows are sometimes 1 higher than they should
43# be in the related resultset.
d3cceebf 44my $artist=$schema->resultset('Artist')->create({name => 'xxx'});
b683f352 45is($artist->related_resultset('cds')->count(), 0, "No CDs found for a shiny new artist");
46is(scalar($artist->related_resultset('cds')->all()), 0, "No CDs fetched for a shiny new artist");
47
d3cceebf 48my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id});
b683f352 49is($artist_rs->related_resultset('cds')->count(), 0, "No CDs counted for a shiny new artist using a resultset search");
50is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched for a shiny new artist using a resultset search");
6aa93928 51
52done_testing;