Extra test of UNIVERSAL handling in describe_class_methods
[dbsrgits/DBIx-Class.git] / t / count / joined.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
21bd38f8 3use strict;
4use warnings;
5
6use Test::More;
21bd38f8 7use DBICTest;
8
21bd38f8 9my $schema = DBICTest->init_schema();
10
a258ee5d 11my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } });
12cmp_ok($cds->count, '>', 1, "extra joins explode entity count");
13
6aa93928 14for my $arg (
15 [ 'prefetch-collapsed has_many' => { prefetch => 'cd_to_producer' } ],
16 [ 'distict-collapsed result' => { distinct => 1 } ],
17 [ 'explicit collapse request' => { collapse => 1 } ],
18) {
19 for my $hri (0,1) {
20 my $diag = $arg->[0] . ($hri ? ' with HRI' : '');
21
22 my $rs = $cds->search({}, {
23 %{$arg->[1]},
24 $hri ? ( result_class => 'DBIx::Class::ResultClass::HashRefInflator' ) : (),
25 });
26
27 is
28 $rs->count,
29 1,
30 "Count correct on $diag",
31 ;
32
33 is
34 scalar $rs->all,
35 1,
36 "Amount of constructed objects matches count on $diag",
37 ;
38 }
39}
a258ee5d 40
b683f352 41# JOIN and LEFT JOIN issues mean that we've seen problems where counted rows and fetched rows are sometimes 1 higher than they should
42# be in the related resultset.
d3cceebf 43my $artist=$schema->resultset('Artist')->create({name => 'xxx'});
b683f352 44is($artist->related_resultset('cds')->count(), 0, "No CDs found for a shiny new artist");
45is(scalar($artist->related_resultset('cds')->all()), 0, "No CDs fetched for a shiny new artist");
46
d3cceebf 47my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id});
b683f352 48is($artist_rs->related_resultset('cds')->count(), 0, "No CDs counted for a shiny new artist using a resultset search");
49is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched for a shiny new artist using a resultset search");
6aa93928 50
51done_testing;