11 my $schema = DBICTest->init_schema();
14 # while cds.* will be selected anyway (prefetch currently forces the result of _resolve_prefetch)
15 # only the requested me.name column will be fetched.
17 # reference sql with select => [...]
18 # SELECT me.name, cds.title, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track FROM ...
20 my $rs = $schema->resultset('Artist')->search(
21 { 'cds.title' => { '!=', 'Generic Manufactured Singles' } },
23 prefetch => [ qw/ cds / ],
24 order_by => [ { -desc => 'me.name' }, 'cds.title' ],
25 select => [qw/ me.name cds.title / ],
29 is ($rs->count, 2, 'Correct number of collapsed artists');
30 my $we_are_goth = $rs->first;
31 is ($we_are_goth->name, 'We Are Goth', 'Correct first artist');
32 is ($we_are_goth->cds->count, 1, 'Correct number of CDs for first artist');
33 is ($we_are_goth->cds->first->title, 'Come Be Depressed With Us', 'Correct cd for artist');
34 }, 'explicit prefetch on a keyless object works');
38 # test implicit prefetch as well
40 my $rs = $schema->resultset('CD')->search(
41 { title => 'Generic Manufactured Singles' },
44 select => [qw/ me.title artist.name / ],
49 is ($cd->title, 'Generic Manufactured Singles', 'CD title prefetched correctly');
50 isa_ok ($cd->artist, 'DBICTest::Artist');
51 is ($cd->artist->name, 'Random Boy Band', 'Artist object has correct name');
53 }, 'implicit keyless prefetch works');