Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
21bd38f8 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
21bd38f8 |
7 | use DBICTest; |
8 | |
21bd38f8 |
9 | my $schema = DBICTest->init_schema(); |
10 | |
a258ee5d |
11 | my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } }); |
12 | cmp_ok($cds->count, '>', 1, "extra joins explode entity count"); |
13 | |
6aa93928 |
14 | for 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 |
43 | my $artist=$schema->resultset('Artist')->create({name => 'xxx'}); |
b683f352 |
44 | is($artist->related_resultset('cds')->count(), 0, "No CDs found for a shiny new artist"); |
45 | is(scalar($artist->related_resultset('cds')->all()), 0, "No CDs fetched for a shiny new artist"); |
46 | |
d3cceebf |
47 | my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id}); |
b683f352 |
48 | is($artist_rs->related_resultset('cds')->count(), 0, "No CDs counted for a shiny new artist using a resultset search"); |
49 | is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched for a shiny new artist using a resultset search"); |
6aa93928 |
50 | |
51 | done_testing; |