8 my $schema = DBICTest->init_schema();
9 my $sdebug = $schema->storage->debug;
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 my ( $pr_tracks_rs, $pr_tracks_count );
21 $schema->storage->debugcb( sub { $queries++ } );
22 $schema->storage->debug(1);
26 local $SIG{__WARN__} = sub { $o_mm_warn = shift };
27 $pr_tracks_rs = $pr_cd_rs->first->tracks;
29 $pr_tracks_count = $pr_tracks_rs->count;
32 'no warning on attempt to prefetch several same level has_many\'s (1 -> M + M)'
35 is( $queries, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
36 $schema->storage->debugcb(undef);
37 $schema->storage->debug($sdebug);
39 is( $pr_tracks_count, $tracks_count,
40 'equal count of prefetched relations over several same level has_many\'s (1 -> M + M)'
42 is( $pr_tracks_rs->all, $tracks_rs->all,
43 'equal amount of objects returned with and without prefetch over several same level has_many\'s (1 -> M + M)'
48 $schema->resultset('LinerNotes')->search( { notes => 'Buy Whiskey!' } );
50 $note_rs->search( {}, { prefetch => { cd => [qw/tracks tags/] }, } );
52 my $tags_rs = $note_rs->first->cd->tags;
53 my $tags_count = $tags_rs->count;
55 my ( $pr_tags_rs, $pr_tags_count );
58 $schema->storage->debugcb( sub { $queries++ } );
59 $schema->storage->debug(1);
63 local $SIG{__WARN__} = sub { $m_o_mm_warn = shift };
64 $pr_tags_rs = $pr_note_rs->first->cd->tags;
66 $pr_tags_count = $pr_tags_rs->count;
69 'no warning on attempt to prefetch several same level has_many\'s (M -> 1 -> M + M)'
72 is( $queries, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
73 $schema->storage->debugcb(undef);
74 $schema->storage->debug($sdebug);
76 is( $pr_tags_count, $tags_count,
77 'equal count of prefetched relations over several same level has_many\'s (M -> 1 -> M + M)'
79 is( $pr_tags_rs->all, $tags_rs->all,
80 'equal amount of objects with and without prefetch over several same level has_many\'s (M -> 1 -> M + M)'