Simplify unresolvable test by arcanez
[dbsrgits/DBIx-Class.git] / t / prefetch / unresolvable.t
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
9 plan tests => 5;
10
11 my $schema = DBICTest->init_schema();
12
13 lives_ok(sub {
14
15 #  use Data::Dumper;
16 #  warn Dumper [$schema->resultset('Artist')->search ({}, { prefetch => 'cds' })->hri_dump->all];
17
18
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)
21
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 ...
24
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   );
33
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');
39
40 });