Commit | Line | Data |
9ae300a4 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
8 | my $schema = DBICTest->init_schema(); |
9 | |
10 | my $art = $schema->resultset('Artist')->find( |
11 | { 'me.artistid' => 1 }, |
12 | { prefetch => 'cds', order_by => { -desc => 'cds.year' } } |
13 | ); |
14 | |
15 | is ( |
16 | $art->cds->search({ year => 1999 })->next->year, |
17 | 1999, |
18 | 'Found expected CD with year 1999 after refined search', |
19 | ); |
20 | |
21 | is ( |
22 | $art->cds->count({ year => 1999 }), |
23 | 1, |
24 | 'Correct refined count', |
25 | ); |
26 | |
27 | # this still should emit no queries: |
49eeb48d |
28 | $schema->is_executed_querycount( sub { |
9ae300a4 |
29 | |
30 | my $cds = $art->cds; |
31 | is ( |
32 | $cds->count, |
33 | 3, |
34 | 'Correct prefetched count', |
35 | ); |
36 | |
37 | my @years = qw(2001 1999 1997); |
38 | while (my $cd = $cds->next) { |
39 | is ( |
40 | $cd->year, |
41 | (shift @years), |
42 | 'Correct prefetched cd year', |
43 | ); |
44 | } |
45 | |
49eeb48d |
46 | }, 0, 'No queries on prefetched operations'); |
9ae300a4 |
47 | |
48 | done_testing; |