1 # Test to ensure we get a consistent result set wether or not we use the
2 # prefetch option in combination rows (LIMIT).
13 my $schema = DBICTest->init_schema();
16 my $no_prefetch = $schema->resultset('Artist')->search(
17 [ # search deliberately contrived
18 { 'artwork.cd_id' => undef },
19 { 'tracks.title' => { '!=' => 'blah-blah-1234568' }}
21 { rows => 3, join => { cds => [qw/artwork tracks/] },
25 my $use_prefetch = $no_prefetch->search(
29 order_by => { -desc => 'name' },
33 is($no_prefetch->count, $use_prefetch->count, '$no_prefetch->count == $use_prefetch->count');
35 scalar ($no_prefetch->all),
36 scalar ($use_prefetch->all),
37 "Amount of returned rows is right"
40 my $artist_many_cds = $schema->resultset('Artist')->search ( {}, {
42 group_by => 'me.artistid',
43 having => \ 'count(cds.cdid) > 1',
47 $no_prefetch = $schema->resultset('Artist')->search(
48 { artistid => $artist_many_cds->id },
52 $use_prefetch = $no_prefetch->search ({}, { prefetch => 'cds' });
54 my $normal_artist = $no_prefetch->single;
55 my $prefetch_artist = $use_prefetch->find({ name => $artist_many_cds->name });
56 my $prefetch2_artist = $use_prefetch->first;
59 $prefetch_artist->cds->count,
60 $normal_artist->cds->count,
61 "Count of child rel with prefetch + rows => 1 is right (find)"
64 $prefetch2_artist->cds->count,
65 $normal_artist->cds->count,
66 "Count of child rel with prefetch + rows => 1 is right (first)"
70 scalar ($prefetch_artist->cds->all),
71 scalar ($normal_artist->cds->all),
72 "Amount of child rel rows with prefetch + rows => 1 is right (find)"
75 scalar ($prefetch2_artist->cds->all),
76 scalar ($normal_artist->cds->all),
77 "Amount of child rel rows with prefetch + rows => 1 is right (first)"
81 sub { $use_prefetch->single },
82 qr/resultsets prefetching has_many/,
83 'single() with multiprefetch is illegal',
86 my $artist = $use_prefetch->search({'cds.title' => $artist_many_cds->cds->first->title })->next;
87 is($artist->cds->count, 1, "count on search limiting prefetched has_many");
89 # try with double limit
90 my $artist2 = $use_prefetch->search({'cds.title' => { '!=' => $artist_many_cds->cds->first->title } })->slice (0,0)->next;
91 is($artist2->cds->count, 2, "count on search limiting prefetched has_many");