Commit | Line | Data |
9f6555d3 |
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 | my $schema = DBICTest->init_schema(); |
10 | |
11 | my $mo_rs = $schema->resultset('Artist')->search( |
12 | { 'me.artistid' => 4 }, |
13 | { |
14 | prefetch => [ |
15 | { |
16 | cds => [ |
17 | { tracks => { cd_single => 'tracks' } }, |
18 | { cd_to_producer => 'producer' } |
19 | ] |
20 | }, |
21 | { artwork_to_artist => 'artwork' } |
22 | ], |
23 | |
24 | result_class => 'DBIx::Class::ResultClass::HashRefInflator', |
908aa1bb |
25 | |
26 | order_by => [qw/tracks.position tracks.trackid producer.producerid/], |
9f6555d3 |
27 | } |
28 | ); |
29 | |
9f6555d3 |
30 | $schema->resultset('Artist')->create( |
31 | { |
32 | name => 'mo', |
33 | rank => '1337', |
34 | cds => [ |
35 | { |
36 | title => 'Song of a Foo', |
37 | year => '1999', |
38 | tracks => [ |
39 | { |
40 | title => 'Foo Me Baby One More Time', |
41 | }, |
42 | { |
43 | title => 'Foo Me Baby One More Time II', |
44 | }, |
45 | { |
46 | title => 'Foo Me Baby One More Time III', |
47 | }, |
48 | { |
49 | title => 'Foo Me Baby One More Time IV', |
50 | cd_single => |
51 | { artist => 1, title => 'MO! Single', year => 2021, tracks => [ |
52 | { title => 'singled out' }, { title => 'still alone' }, |
53 | ] }, |
54 | } |
55 | ], |
56 | cd_to_producer => [ |
57 | { producer => { name => 'riba' } }, |
58 | { producer => { name => 'sushi' } }, |
59 | ] |
60 | }, |
61 | { |
62 | title => 'Song of a Foo II', |
63 | year => '2002', |
64 | tracks => [ |
65 | { |
66 | title => 'Quit Playing Games With My Heart', |
67 | }, |
68 | { |
69 | title => 'Bar Foo', |
70 | }, |
71 | { |
72 | title => 'Foo Bar', |
73 | cd_single => |
74 | { artist => 2, title => 'MO! Single', year => 2020, tracks => [ |
75 | { title => 'singled out' }, { title => 'still alone' }, |
76 | ] }, |
77 | } |
78 | ], |
79 | cd_to_producer => [ |
80 | { producer => { name => 'riba' } }, |
81 | { producer => { name => 'sushi' } }, |
82 | ], |
83 | } |
84 | ], |
85 | artwork_to_artist => |
86 | [ { artwork => { cd_id => 1 } }, { artwork => { cd_id => 2 } } ] |
87 | } |
88 | ); |
89 | |
90 | my $mo = $mo_rs->next; |
91 | |
92 | is( @{$mo->{cds}}, 2, 'two CDs' ); |
93 | |
94 | is_deeply( |
95 | $mo, |
96 | { |
97 | 'cds' => [ |
98 | { |
99 | 'single_track' => undef, |
100 | 'tracks' => [ |
101 | { |
9f6555d3 |
102 | 'cd' => '6', |
103 | 'position' => '1', |
104 | 'trackid' => '19', |
105 | 'title' => 'Foo Me Baby One More Time', |
106 | 'cd_single' => undef, |
107 | 'last_updated_on' => undef, |
108 | 'last_updated_at' => undef |
109 | }, |
110 | { |
9f6555d3 |
111 | 'cd' => '6', |
112 | 'position' => '2', |
113 | 'trackid' => '20', |
114 | 'title' => 'Foo Me Baby One More Time II', |
115 | 'cd_single' => undef, |
116 | 'last_updated_on' => undef, |
117 | 'last_updated_at' => undef |
118 | }, |
119 | { |
9f6555d3 |
120 | 'cd' => '6', |
121 | 'position' => '3', |
122 | 'trackid' => '21', |
123 | 'title' => 'Foo Me Baby One More Time III', |
124 | 'cd_single' => undef, |
125 | 'last_updated_on' => undef, |
126 | 'last_updated_at' => undef |
127 | }, |
128 | { |
9f6555d3 |
129 | 'cd' => '6', |
130 | 'position' => '4', |
131 | 'trackid' => '22', |
132 | 'title' => 'Foo Me Baby One More Time IV', |
133 | 'last_updated_on' => undef, |
134 | 'last_updated_at' => undef, |
135 | 'cd_single' => { |
136 | 'single_track' => '22', |
137 | 'artist' => '1', |
138 | 'cdid' => '7', |
139 | 'title' => 'MO! Single', |
140 | 'genreid' => undef, |
141 | 'year' => '2021', |
142 | 'tracks' => [ |
143 | { |
9f6555d3 |
144 | 'cd' => '7', |
145 | 'position' => '1', |
146 | 'title' => 'singled out', |
147 | 'trackid' => '23', |
148 | 'last_updated_at' => undef, |
149 | 'last_updated_on' => undef |
150 | }, |
151 | { |
9f6555d3 |
152 | 'cd' => '7', |
153 | 'position' => '2', |
154 | 'title' => 'still alone', |
155 | 'trackid' => '24', |
156 | 'last_updated_at' => undef, |
157 | 'last_updated_on' => undef |
158 | }, |
159 | ], |
160 | }, |
161 | } |
162 | ], |
163 | 'artist' => '4', |
164 | 'cdid' => '6', |
165 | 'cd_to_producer' => [ |
166 | { |
167 | 'attribute' => undef, |
168 | 'cd' => '6', |
169 | 'producer' => { |
170 | 'name' => 'riba', |
171 | 'producerid' => '4' |
172 | } |
173 | }, |
174 | { |
175 | 'attribute' => undef, |
176 | 'cd' => '6', |
177 | 'producer' => { |
178 | 'name' => 'sushi', |
179 | 'producerid' => '5' |
180 | } |
181 | } |
182 | ], |
183 | 'title' => 'Song of a Foo', |
184 | 'genreid' => undef, |
185 | 'year' => '1999' |
186 | }, |
187 | { |
188 | 'single_track' => undef, |
189 | 'tracks' => [ |
9f6555d3 |
190 | { |
9f6555d3 |
191 | 'cd' => '8', |
192 | 'position' => '1', |
193 | 'trackid' => '25', |
194 | 'title' => 'Quit Playing Games With My Heart', |
195 | 'last_updated_on' => undef, |
196 | 'last_updated_at' => undef, |
197 | 'cd_single' => undef, |
198 | }, |
199 | { |
908aa1bb |
200 | 'cd' => '8', |
201 | 'position' => '2', |
202 | 'trackid' => '26', |
203 | 'title' => 'Bar Foo', |
204 | 'cd_single' => undef, |
205 | 'last_updated_on' => undef, |
206 | 'last_updated_at' => undef |
207 | }, |
208 | { |
9f6555d3 |
209 | 'cd' => '8', |
210 | 'position' => '3', |
211 | 'trackid' => '27', |
212 | 'title' => 'Foo Bar', |
213 | 'last_updated_on' => undef, |
214 | 'last_updated_at' => undef, |
215 | 'cd_single' => { |
216 | 'single_track' => '27', |
217 | 'artist' => '2', |
218 | 'cdid' => '9', |
219 | 'title' => 'MO! Single', |
220 | 'genreid' => undef, |
221 | 'year' => '2020', |
222 | 'tracks' => [ |
223 | { |
9f6555d3 |
224 | 'cd' => '9', |
225 | 'position' => '1', |
226 | 'title' => 'singled out', |
227 | 'trackid' => '28', |
228 | 'last_updated_at' => undef, |
229 | 'last_updated_on' => undef |
230 | }, |
231 | { |
9f6555d3 |
232 | 'cd' => '9', |
233 | 'position' => '2', |
234 | 'title' => 'still alone', |
235 | 'trackid' => '29', |
236 | 'last_updated_at' => undef, |
237 | 'last_updated_on' => undef |
238 | }, |
239 | ], |
240 | |
241 | }, |
242 | }, |
243 | ], |
244 | 'artist' => '4', |
245 | 'cdid' => '8', |
246 | 'cd_to_producer' => [ |
247 | { |
248 | 'attribute' => undef, |
249 | 'cd' => '8', |
250 | 'producer' => { |
251 | 'name' => 'riba', |
252 | 'producerid' => '4' |
253 | } |
254 | }, |
255 | { |
256 | 'attribute' => undef, |
257 | 'cd' => '8', |
258 | 'producer' => { |
259 | 'name' => 'sushi', |
260 | 'producerid' => '5' |
261 | } |
262 | } |
263 | ], |
264 | 'title' => 'Song of a Foo II', |
265 | 'genreid' => undef, |
266 | 'year' => '2002' |
267 | } |
268 | ], |
269 | 'artistid' => '4', |
270 | 'charfield' => undef, |
271 | 'name' => 'mo', |
272 | 'artwork_to_artist' => [ |
273 | { |
274 | 'artwork' => { 'cd_id' => '1' }, |
275 | 'artist_id' => '4', |
276 | 'artwork_cd_id' => '1' |
277 | }, |
278 | { |
279 | 'artwork' => { 'cd_id' => '2' }, |
280 | 'artist_id' => '4', |
281 | 'artwork_cd_id' => '2' |
282 | } |
283 | ], |
284 | 'rank' => '1337' |
285 | } |
286 | ); |
287 | |
288 | done_testing; |