9 my $schema = DBICTest->init_schema();
12 my $cd_rs = $schema->resultset('CD')->search( { 'me.title' => 'Forkful of bees' } );
13 my $pr_cd_rs = $cd_rs->search( {}, { prefetch => [qw/tracks tags/], } );
15 my $tracks_rs = $cd_rs->first->tracks;
16 my $tracks_count = $tracks_rs->count;
18 $schema->is_executed_querycount( sub {
23 $pr_tracks_rs = $pcr->first->tracks;
24 } [], 'no warning on attempt to prefetch several same level has_many\'s (1 -> M + M)' ;
26 is( $pr_tracks_rs->count, $tracks_count,
27 'equal count of prefetched relations over several same level has_many\'s (1 -> M + M)'
30 is( $pr_tracks_rs->all, $tracks_count,
31 'equal amount of objects returned with and without prefetch over several same level has_many\'s (1 -> M + M)'
34 }, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
39 $schema->resultset('LinerNotes')->search( { notes => 'Buy Whiskey!' } );
41 $note_rs->search( {}, { prefetch => { cd => [qw/tracks tags/] }, } );
43 my $tags_rs = $note_rs->first->cd->tags;
44 my $tags_count = $tags_rs->count;
46 $schema->is_executed_querycount( sub {
47 my $pnr = $pr_note_rs;
51 $pr_tags_rs = $pnr->first->cd->tags;
52 } [], 'no warning on attempt to prefetch several same level has_many\'s (M -> 1 -> M + M)';
54 is( $pr_tags_rs->count, $tags_count,
55 'equal count of prefetched relations over several same level has_many\'s (M -> 1 -> M + M)'
57 is( $pr_tags_rs->all, $tags_count,
58 'equal amount of objects with and without prefetch over several same level has_many\'s (M -> 1 -> M + M)'
61 }, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );