10 my $schema = DBICTest->init_schema();
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');
17 my $orig_cb = $schema->storage->debugcb;
18 $schema->storage->debugcb(sub { $queries++ });
19 $schema->storage->debug(1);
22 my $pref = $schema->resultset ('Artist')
23 ->search ({ 'me.artistid' => $artist->id }, { prefetch => { cds => 'genre' } })
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');
30 is ($queries, 1, 'All happened within one query only');
31 $schema->storage->debugcb($orig_cb);
32 $schema->storage->debug(0);