Commit | Line | Data |
a04af85f |
1 | # Test to ensure we get a consistent result set wether or not we use the |
2 | # prefetch option in combination rows (LIMIT). |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
51a296b4 |
10 | plan tests => 4; |
a04af85f |
11 | |
12 | my $schema = DBICTest->init_schema(); |
51a296b4 |
13 | |
14 | |
a04af85f |
15 | my $no_prefetch = $schema->resultset('Artist')->search( |
25cac750 |
16 | undef, |
17 | { rows => 3 } |
a04af85f |
18 | ); |
19 | |
20 | my $use_prefetch = $schema->resultset('Artist')->search( |
51a296b4 |
21 | [ # search deliberately contrived |
22 | { 'artwork.cd_id' => undef }, |
23 | { 'tracks.title' => { '!=' => 'blah-blah-1234568' }} |
24 | ], |
25cac750 |
25 | { |
26 | prefetch => 'cds', |
51a296b4 |
27 | join => { cds => [qw/artwork tracks/] }, |
28 | rows => 3, |
29 | order_by => { -desc => 'name' }, |
25cac750 |
30 | } |
a04af85f |
31 | ); |
32 | |
a04af85f |
33 | is($no_prefetch->count, $use_prefetch->count, '$no_prefetch->count == $use_prefetch->count'); |
5624ba1f |
34 | is( |
9117ccfb |
35 | scalar ($no_prefetch->all), |
36 | scalar ($use_prefetch->all), |
37 | "Amount of returned rows is right" |
5624ba1f |
38 | ); |
39 | |
9117ccfb |
40 | my $artist_many_cds = $schema->resultset('Artist')->search ( {}, { |
41 | join => 'cds', |
42 | group_by => 'me.artistid', |
43 | having => \ 'count(cds.cdid) > 1', |
44 | })->first; |
45 | |
46 | |
5624ba1f |
47 | $no_prefetch = $schema->resultset('Artist')->search( |
9117ccfb |
48 | { artistid => $artist_many_cds->id }, |
5624ba1f |
49 | { rows => 1 } |
50 | ); |
51 | |
52 | $use_prefetch = $schema->resultset('Artist')->search( |
9117ccfb |
53 | { artistid => $artist_many_cds->id }, |
5624ba1f |
54 | { |
55 | prefetch => 'cds', |
56 | rows => 1 |
57 | } |
58 | ); |
59 | |
60 | my $prefetch_artist = $use_prefetch->first; |
61 | my $normal_artist = $no_prefetch->first; |
62 | |
63 | is( |
64 | $prefetch_artist->cds->count, |
65 | $normal_artist->cds->count, |
66 | "Count of child rel with prefetch + rows => 1 is right" |
67 | ); |
9117ccfb |
68 | is ( |
69 | scalar ($prefetch_artist->cds->all), |
70 | scalar ($normal_artist->cds->all), |
71 | "Amount of child rel rows with prefetch + rows => 1 is right" |
72 | ); |