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(
21 my $use_prefetch = $schema->resultset('Artist')->search(
22 [ # search deliberately contrived
23 { 'artwork.cd_id' => undef },
24 { 'tracks.title' => { '!=' => 'blah-blah-1234568' }}
28 join => { cds => [qw/artwork tracks/] },
30 order_by => { -desc => 'name' },
34 is($no_prefetch->count, $use_prefetch->count, '$no_prefetch->count == $use_prefetch->count');
36 scalar ($no_prefetch->all),
37 scalar ($use_prefetch->all),
38 "Amount of returned rows is right"
41 my $artist_many_cds = $schema->resultset('Artist')->search ( {}, {
43 group_by => 'me.artistid',
44 having => \ 'count(cds.cdid) > 1',
48 $no_prefetch = $schema->resultset('Artist')->search(
49 { artistid => $artist_many_cds->id },
53 $use_prefetch = $no_prefetch->search ({}, { prefetch => 'cds' });
55 my $normal_artist = $no_prefetch->single;
56 my $prefetch_artist = $use_prefetch->find({ name => $artist_many_cds->name });
57 my $prefetch2_artist = $use_prefetch->first;
60 $prefetch_artist->cds->count,
61 $normal_artist->cds->count,
62 "Count of child rel with prefetch + rows => 1 is right (find)"
65 $prefetch2_artist->cds->count,
66 $normal_artist->cds->count,
67 "Count of child rel with prefetch + rows => 1 is right (first)"
71 scalar ($prefetch_artist->cds->all),
72 scalar ($normal_artist->cds->all),
73 "Amount of child rel rows with prefetch + rows => 1 is right (find)"
76 scalar ($prefetch2_artist->cds->all),
77 scalar ($normal_artist->cds->all),
78 "Amount of child rel rows with prefetch + rows => 1 is right (first)"
82 sub { $use_prefetch->single },
83 qr/resultsets prefetching has_many/,
84 'single() with multiprefetch is illegal',