10 my $schema = DBICTest->init_schema();
13 my $rs = $schema->resultset("Artwork")->search(undef, {distinct => 1})
14 ->search_related('artwork_to_artist')->search_related('artist',
16 { prefetch => 'cds' },
18 is($rs->all, 0, 'prefetch without WHERE (objects)');
19 is($rs->count, 0, 'prefetch without WHERE (count)');
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' },
26 is($rs->all, 0, 'prefetch with WHERE (objects)');
27 is($rs->count, 0, 'prefetch with WHERE (count)');
30 # test where conditions at the root of the related chain
31 my $artist_rs = $schema->resultset("Artist")->search({artistid => 11});
34 $rs = $artist_rs->search_related('cds')->search_related('genre',
35 { 'genre.name' => 'foo' },
36 { prefetch => 'cds' },
38 is($rs->all, 0, 'prefetch without distinct (objects)');
39 is($rs->count, 0, 'prefetch without distinct (count)');
43 $rs = $artist_rs->search(undef, {distinct => 1})
44 ->search_related('cds')->search_related('genre',
45 { 'genre.name' => 'foo' },
47 is($rs->all, 0, 'distinct without prefetch (objects)');
48 is($rs->count, 0, 'distinct without prefetch (count)');
52 $rs = $artist_rs->search({}, {distinct => 1})
53 ->search_related('cds')->search_related('genre',
54 { 'genre.name' => 'foo' },
55 { prefetch => 'cds' },
57 is($rs->all, 0, 'distinct with prefetch (objects)');
58 is($rs->count, 0, 'distinct with prefetch (count)');
62 }, 'distinct generally works with prefetch');