Commit | Line | Data |
13d06949 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
10 | my $schema = DBICTest->init_schema(); |
11 | |
12 | my $artist = $schema->resultset ('Artist')->find ({artistid => 1}); |
13 | is ($artist->cds->count, 3, 'Correct number of CDs'); |
14 | is ($artist->cds->search_related ('genre')->count, 1, 'Only one of the cds has a genre'); |
15 | |
16 | my $queries = 0; |
17 | my $orig_cb = $schema->storage->debugcb; |
18 | $schema->storage->debugcb(sub { $queries++ }); |
19 | $schema->storage->debug(1); |
20 | |
21 | |
22 | my $pref = $schema->resultset ('Artist') |
23 | ->search ({ 'me.artistid' => $artist->id }, { prefetch => { cds => 'genre' } }) |
24 | ->next; |
25 | |
26 | is ($pref->cds->count, 3, 'Correct number of CDs prefetched'); |
27 | is ($pref->cds->search_related ('genre')->count, 1, 'Only one of the prefetched cds has a prefetched genre'); |
28 | |
29 | |
30 | is ($queries, 1, 'All happened within one query only'); |
31 | $schema->storage->debugcb($orig_cb); |
32 | $schema->storage->debug(0); |
33 | |
34 | |
35 | done_testing; |