Test for restricted prefetch (now passing again after previous commit)
[dbsrgits/DBIx-Class.git] / t / prefetch / restricted_children_set.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my $schema = DBICTest->init_schema();
9
10 my $cds_rs = $schema->resultset('CD')->search(
11   [
12     {
13       'me.title' => "Caterwaulin' Blues",
14       'cds.title' => { '!=' => 'Forkful of bees' }
15     },
16     {
17       'me.title' => { '!=', => "Caterwaulin' Blues" },
18       'cds.title' => 'Forkful of bees'
19     },
20   ],
21   {
22     order_by => 'me.cdid',
23     prefetch => { artist => 'cds' },
24     result_class => 'DBIx::Class::ResultClass::HashRefInflator',
25   },
26 );
27
28 is_deeply [ $cds_rs->all ], [
29   {
30     'single_track' => undef,
31     'cdid' => '1',
32     'artist' => {
33       'cds' => [
34         {
35           'single_track' => undef,
36           'artist' => '1',
37           'cdid' => '2',
38           'title' => 'Forkful of bees',
39           'genreid' => undef,
40           'year' => '2001'
41         },
42       ],
43       'artistid' => '1',
44       'charfield' => undef,
45       'name' => 'Caterwauler McCrae',
46       'rank' => '13'
47     },
48     'title' => 'Spoonful of bees',
49     'year' => '1999',
50     'genreid' => '1'
51   },
52   {
53     'single_track' => undef,
54     'cdid' => '2',
55     'artist' => {
56       'cds' => [
57         {
58           'single_track' => undef,
59           'artist' => '1',
60           'cdid' => '2',
61           'title' => 'Forkful of bees',
62           'genreid' => undef,
63           'year' => '2001'
64         },
65       ],
66       'artistid' => '1',
67       'charfield' => undef,
68       'name' => 'Caterwauler McCrae',
69       'rank' => '13'
70     },
71     'title' => 'Forkful of bees',
72     'year' => '2001',
73     'genreid' => undef
74   },
75   {
76     'single_track' => undef,
77     'cdid' => '3',
78     'artist' => {
79       'cds' => [
80         {
81           'single_track' => undef,
82           'artist' => '1',
83           'cdid' => '3',
84           'title' => 'Caterwaulin\' Blues',
85           'genreid' => undef,
86           'year' => '1997'
87         },
88         {
89           'single_track' => undef,
90           'artist' => '1',
91           'cdid' => '1',
92           'title' => 'Spoonful of bees',
93           'genreid' => '1',
94           'year' => '1999'
95         }
96       ],
97       'artistid' => '1',
98       'charfield' => undef,
99       'name' => 'Caterwauler McCrae',
100       'rank' => '13'
101     },
102     'title' => 'Caterwaulin\' Blues',
103     'year' => '1997',
104     'genreid' => undef
105   }
106 ], 'multi-level prefetch with restrictions ok';
107
108 done_testing;