Expand annotations to cover all generated methods
[dbsrgits/DBIx-Class.git] / t / prefetch / multiple_hasmany.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Warn;
8
9 use DBICTest;
10
11 my $schema = DBICTest->init_schema();
12
13 #( 1 -> M + M )
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/], } );
16
17 my $tracks_rs    = $cd_rs->first->tracks;
18 my $tracks_count = $tracks_rs->count;
19
20 $schema->is_executed_querycount( sub {
21   my $pcr = $pr_cd_rs;
22   my $pr_tracks_rs;
23
24   warnings_exist {
25     $pr_tracks_rs = $pcr->first->tracks;
26   } [], 'no warning on attempt to prefetch several same level has_many\'s (1 -> M + M)' ;
27
28   is( $pr_tracks_rs->count, $tracks_count,
29     'equal count of prefetched relations over several same level has_many\'s (1 -> M + M)'
30   );
31
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)'
34   );
35
36 }, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
37
38
39 #( M -> 1 -> M + M )
40 my $note_rs =
41   $schema->resultset('LinerNotes')->search( { notes => 'Buy Whiskey!' } );
42 my $pr_note_rs =
43   $note_rs->search( {}, { prefetch => { cd => [qw/tracks tags/] }, } );
44
45 my $tags_rs    = $note_rs->first->cd->tags;
46 my $tags_count = $tags_rs->count;
47
48 $schema->is_executed_querycount( sub {
49   my $pnr = $pr_note_rs;
50   my $pr_tags_rs;
51
52   warnings_exist {
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)';
55
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)'
58   );
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)'
61   );
62
63 }, 1, 'prefetch one->(has_many,has_many) ran exactly 1 query' );
64
65
66 done_testing;