9 my $schema = DBICTest->init_schema();
10 my $sdebug = $schema->storage->debug;
13 my $cd_rs = $schema->resultset('CD')->search( { 'me.title' => 'Forkful of bees' } );
14 my $pr_cd_rs = $cd_rs->search( {}, { prefetch => [qw/tracks tags/], } );
16 my $tracks_rs = $cd_rs->first->tracks;
17 my $tracks_count = $tracks_rs->count;
19 my ( $pr_tracks_rs, $pr_tracks_count );
22 $schema->storage->debugcb( sub { $queries++ } );
23 $schema->storage->debug(1);
27 local $SIG{__WARN__} = sub { $o_mm_warn = shift };
28 $pr_tracks_rs = $pr_cd_rs->first->tracks;
30 $pr_tracks_count = $pr_tracks_rs->count;
33 'no warning on attempt to prefetch several same level has_many\'s (1 -> M + M)'
36 is( $queries, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
37 $schema->storage->debugcb(undef);
38 $schema->storage->debug($sdebug);
40 is( $pr_tracks_count, $tracks_count,
41 'equal count of prefetched relations over several same level has_many\'s (1 -> M + M)'
43 is( $pr_tracks_rs->all, $tracks_rs->all,
44 'equal amount of objects returned with and without prefetch over several same level has_many\'s (1 -> M + M)'
49 $schema->resultset('LinerNotes')->search( { notes => 'Buy Whiskey!' } );
51 $note_rs->search( {}, { prefetch => { cd => [qw/tracks tags/] }, } );
53 my $tags_rs = $note_rs->first->cd->tags;
54 my $tags_count = $tags_rs->count;
56 my ( $pr_tags_rs, $pr_tags_count );
59 $schema->storage->debugcb( sub { $queries++ } );
60 $schema->storage->debug(1);
64 local $SIG{__WARN__} = sub { $m_o_mm_warn = shift };
65 $pr_tags_rs = $pr_note_rs->first->cd->tags;
67 $pr_tags_count = $pr_tags_rs->count;
70 'no warning on attempt to prefetch several same level has_many\'s (M -> 1 -> M + M)'
73 is( $queries, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
74 $schema->storage->debugcb(undef);
75 $schema->storage->debug($sdebug);
77 is( $pr_tags_count, $tags_count,
78 'equal count of prefetched relations over several same level has_many\'s (M -> 1 -> M + M)'
80 is( $pr_tags_rs->all, $tags_rs->all,
81 'equal amount of objects with and without prefetch over several same level has_many\'s (M -> 1 -> M + M)'