Commit | Line | Data |
5fc1d686 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
10 | my $schema = DBICTest->init_schema(); |
11 | |
12 | lives_ok (sub { |
13 | my $rs = $schema->resultset("Artwork")->search(undef, {distinct => 1}) |
14 | ->search_related('artwork_to_artist')->search_related('artist', |
15 | undef, |
16 | { prefetch => 'cds' }, |
17 | ); |
18 | is($rs->all, 0, 'prefetch without WHERE (objects)'); |
19 | is($rs->count, 0, 'prefetch without WHERE (count)'); |
20 | |
21 | $rs = $schema->resultset("Artwork")->search(undef, {distinct => 1}) |
22 | ->search_related('artwork_to_artist')->search_related('artist', |
23 | { 'cds.title' => 'foo' }, |
24 | { prefetch => 'cds' }, |
25 | ); |
26 | is($rs->all, 0, 'prefetch with WHERE (objects)'); |
27 | is($rs->count, 0, 'prefetch with WHERE (count)'); |
28 | |
29 | |
30 | # test where conditions at the root of the related chain |
31 | my $artist_rs = $schema->resultset("Artist")->search({artistid => 11}); |
32 | |
33 | |
34 | $rs = $artist_rs->search_related('cds')->search_related('genre', |
35 | { 'genre.name' => 'foo' }, |
36 | { prefetch => 'cds' }, |
37 | ); |
38 | is($rs->all, 0, 'prefetch without distinct (objects)'); |
39 | is($rs->count, 0, 'prefetch without distinct (count)'); |
40 | |
41 | |
42 | |
43 | $rs = $artist_rs->search(undef, {distinct => 1}) |
44 | ->search_related('cds')->search_related('genre', |
45 | { 'genre.name' => 'foo' }, |
46 | ); |
47 | is($rs->all, 0, 'distinct without prefetch (objects)'); |
48 | is($rs->count, 0, 'distinct without prefetch (count)'); |
49 | |
50 | |
51 | |
52 | $rs = $artist_rs->search({}, {distinct => 1}) |
53 | ->search_related('cds')->search_related('genre', |
54 | { 'genre.name' => 'foo' }, |
55 | { prefetch => 'cds' }, |
56 | ); |
57 | is($rs->all, 0, 'distinct with prefetch (objects)'); |
58 | is($rs->count, 0, 'distinct with prefetch (count)'); |
59 | |
60 | |
61 | |
62 | }, 'distinct generally works with prefetch'); |
63 | |
64 | done_testing; |