Initial full test pass - all fetches are eager for now
[dbsrgits/DBIx-Class.git] / t / prefetch / one_to_many_to_one.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 use lib qw(t/lib);
7 use DBICTest;
8
9 my $schema = DBICTest->init_schema();
10
11 my $artist = $schema->resultset ('Artist')->find ({artistid => 1});
12 is ($artist->cds->count, 3, 'Correct number of CDs');
13 is ($artist->cds->search_related ('genre')->count, 1, 'Only one of the cds has a genre');
14
15 my $queries = 0;
16 my $orig_cb = $schema->storage->debugcb;
17 $schema->storage->debugcb(sub { $queries++ });
18 $schema->storage->debug(1);
19
20 my $pref = $schema->resultset ('Artist')
21                      ->search ({ 'me.artistid' => $artist->id }, { prefetch => { cds => 'genre' } })
22                       ->next;
23
24 is ($pref->cds->count, 3, 'Correct number of CDs prefetched');
25 is ($pref->cds->search_related ('genre')->count, 1, 'Only one of the prefetched cds has a prefetched genre');
26
27 is ($queries, 1, 'All happened within one query only');
28 $schema->storage->debugcb($orig_cb);
29 $schema->storage->debug(0);
30
31 done_testing;