Commit | Line | Data |
5aa25b93 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
376b7a93 |
9 | plan tests => 5; |
5aa25b93 |
10 | |
376b7a93 |
11 | my $schema = DBICTest->init_schema(); |
5aa25b93 |
12 | |
376b7a93 |
13 | lives_ok(sub { |
5aa25b93 |
14 | |
376b7a93 |
15 | # use Data::Dumper; |
16 | # warn Dumper [$schema->resultset('Artist')->search ({}, { prefetch => 'cds' })->hri_dump->all]; |
5aa25b93 |
17 | |
5aa25b93 |
18 | |
376b7a93 |
19 | # while cds.* will be selected anyway (prefetch currently forces the result of _resolve_prefetch) |
20 | # only the requested me.name column will be fetched. This somehow does work on 08010 (tested) |
5aa25b93 |
21 | |
376b7a93 |
22 | # reference sql with select => [...] |
23 | # SELECT me.name, cds.title, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track FROM ... |
5aa25b93 |
24 | |
376b7a93 |
25 | my $rs = $schema->resultset('Artist')->search( |
26 | { 'cds.title' => { '!=', 'Generic Manufactured Singles' } }, |
27 | { |
28 | prefetch => [ qw/ cds / ], |
29 | order_by => [ { -desc => 'me.name' }, 'cds.title' ], |
30 | select => [ qw/ me.name cds.title / ], |
31 | } |
32 | ); |
5aa25b93 |
33 | |
376b7a93 |
34 | is ($rs->count, 2, 'Correct number of collapsed artists'); |
35 | my $we_are_goth = $rs->first; |
36 | is ($we_are_goth->name, 'We Are Goth', 'Correct first artist'); |
37 | is ($we_are_goth->cds->count, 1, 'Correct number of CDs for first artist'); |
38 | is ($we_are_goth->cds->first->title, 'Come Be Depressed With Us', 'Correct cd for artist'); |
5aa25b93 |
39 | |
376b7a93 |
40 | }); |