1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
11 my $schema = DBICTest->init_schema();
14 my $cd_rs = $schema->resultset('CD')->search( { 'me.title' => 'Forkful of bees' } );
15 my $pr_cd_rs = $cd_rs->search( {}, { prefetch => [qw/tracks tags/], } );
17 my $tracks_rs = $cd_rs->first->tracks;
18 my $tracks_count = $tracks_rs->count;
20 $schema->is_executed_querycount( sub {
25 $pr_tracks_rs = $pcr->first->tracks;
26 } [], 'no warning on attempt to prefetch several same level has_many\'s (1 -> M + M)' ;
28 is( $pr_tracks_rs->count, $tracks_count,
29 'equal count of prefetched relations over several same level has_many\'s (1 -> M + M)'
32 is( $pr_tracks_rs->all, $tracks_count,
33 'equal amount of objects returned with and without prefetch over several same level has_many\'s (1 -> M + M)'
36 }, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
41 $schema->resultset('LinerNotes')->search( { notes => 'Buy Whiskey!' } );
43 $note_rs->search( {}, { prefetch => { cd => [qw/tracks tags/] }, } );
45 my $tags_rs = $note_rs->first->cd->tags;
46 my $tags_count = $tags_rs->count;
48 $schema->is_executed_querycount( sub {
49 my $pnr = $pr_note_rs;
53 $pr_tags_rs = $pnr->first->cd->tags;
54 } [], 'no warning on attempt to prefetch several same level has_many\'s (M -> 1 -> M + M)';
56 is( $pr_tags_rs->count, $tags_count,
57 'equal count of prefetched relations over several same level has_many\'s (M -> 1 -> M + M)'
59 is( $pr_tags_rs->all, $tags_count,
60 'equal amount of objects with and without prefetch over several same level has_many\'s (M -> 1 -> M + M)'
63 }, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );