10 my $schema = DBICTest->init_schema();
12 my $cd_rs = $schema->resultset('CD')->search (
13 { 'tracks.cd' => { '!=', undef } },
14 { prefetch => ['tracks', 'artist'] },
18 is($cd_rs->count, 5, 'CDs with tracks count');
19 is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (before SELECT()ing)');
21 is($cd_rs->all, 5, 'Amount of CD objects with tracks');
22 is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (after SELECT()ing)');
24 is($cd_rs->search_related ('tracks')->all, 15, 'Track objects associated with CDs (after SELECT()ing)');
26 my $artist = $schema->resultset('Artist')->create({name => 'xxx'});
28 my $artist_rs = $schema->resultset('Artist')->search(
29 {artistid => $artist->id},
30 {prefetch=>'cds', join => 'twokeys' }
33 is($artist_rs->count, 1, "New artist found with prefetch turned on");
34 is(scalar($artist_rs->all), 1, "New artist fetched with prefetch turned on");
35 is($artist_rs->related_resultset('cds')->count, 0, "No CDs counted on a brand new artist");
36 is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched on a brand new artist (count == fetch)");
38 # create a cd, and make sure the non-existing join does not skew the count
39 $artist->create_related ('cds', { title => 'yyy', year => '1999' });
40 is($artist_rs->related_resultset('cds')->count, 1, "1 CDs counted on a brand new artist");
41 is(scalar($artist_rs->related_resultset('cds')->all), 1, "1 CDs prefetched on a brand new artist (count == fetch)");