Commit | Line | Data |
908aa1bb |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
ce556881 |
5 | use Test::Warn; |
908aa1bb |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
ce556881 |
9 | my $new_collapser_version = DBIx::Class::ResultSet->can('_construct_objects'); |
10 | |
908aa1bb |
11 | my $schema = DBICTest->init_schema(no_populate => 1); |
12 | |
742280c7 |
13 | $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{ |
14 | title => 'Magnetic Fields', |
15 | year => 1981, |
16 | genre => { name => 'electro' }, |
17 | tracks => [ |
18 | { title => 'm1' }, |
19 | { title => 'm2' }, |
20 | { title => 'm3' }, |
21 | { title => 'm4' }, |
22 | ], |
23 | } ] }); |
24 | |
908aa1bb |
25 | $schema->resultset('CD')->create({ |
26 | title => 'Equinoxe', |
27 | year => 1978, |
28 | artist => { name => 'JMJ' }, |
29 | genre => { name => 'electro' }, |
30 | tracks => [ |
31 | { title => 'e1' }, |
32 | { title => 'e2' }, |
33 | { title => 'e3' }, |
34 | ], |
35 | single_track => { |
36 | title => 'o1', |
37 | cd => { |
38 | title => 'Oxygene', |
39 | year => 1976, |
742280c7 |
40 | artist => { name => 'JMJ' }, |
908aa1bb |
41 | tracks => [ |
42 | { title => 'o2', position => 2}, # the position should not be needed here, bug in MC |
43 | ], |
44 | }, |
45 | }, |
46 | }); |
47 | |
ce556881 |
48 | $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" }); |
49 | |
908aa1bb |
50 | { |
51 | package DBICTest::_IRCapture; |
52 | sub inflate_result { [@_[2,3]] }; |
53 | } |
54 | |
ce556881 |
55 | { |
56 | package DBICTest::_IRCaptureAround; |
57 | use base 'DBIx::Class::Row'; |
58 | sub inflate_result { [@_[2,3]] }; |
59 | } |
60 | |
61 | warnings_exist |
62 | { $schema->resultset ('CD')->search ({}, { result_class => 'DBICTest::_IRCapture', prefetch => 'tracks' } )->all } |
63 | qr/\QResultClass DBICTest::_IRCapture does not inherit from DBIx::Class::Row and therefore its inflate_result() will receive the full prefetched data tree, without any branch definedness checks/, |
64 | 'Legacy inflate_result() API warned', |
65 | if $new_collapser_version; |
66 | |
67 | cmp_structures( |
908aa1bb |
68 | ([$schema->resultset ('CD')->search ({}, { |
69 | result_class => 'DBICTest::_IRCapture', |
70 | prefetch => { single_track => { cd => 'artist' } }, |
71 | order_by => 'me.cdid', |
72 | })->all]), |
73 | [ |
74 | [ |
75 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
76 | { single_track => [ |
77 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
78 | { cd => [ |
79 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
80 | { |
81 | artist => [ |
82 | { artistid => undef, name => undef, charfield => undef, rank => undef } |
83 | ] |
84 | } |
85 | ] } |
86 | ] } |
87 | ], |
88 | [ |
89 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
90 | { single_track => [ |
91 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
92 | { cd => [ |
93 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
94 | { |
95 | artist => [ |
96 | { artistid => undef, name => undef, charfield => undef, rank => undef } |
97 | ] |
98 | } |
99 | ] } |
100 | ] } |
101 | ], |
102 | [ |
103 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
104 | { single_track => [ |
105 | { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
106 | { cd => [ |
107 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
108 | { |
109 | artist => [ |
110 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 } |
111 | ] |
112 | } |
113 | ] } |
114 | ] } |
115 | ], |
ce556881 |
116 | [ |
117 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
118 | { single_track => [ |
119 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
120 | { cd => [ |
121 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
122 | { |
123 | artist => [ |
124 | { artistid => undef, name => undef, charfield => undef, rank => undef } |
125 | ] |
126 | } |
127 | ] } |
128 | ] } |
129 | ], |
908aa1bb |
130 | ], |
ce556881 |
131 | 'Simple 1:1 descend with classic prefetch legacy' |
908aa1bb |
132 | ); |
133 | |
ce556881 |
134 | cmp_structures( |
135 | ([$schema->resultset ('CD')->search ({}, { |
136 | result_class => 'DBICTest::_IRCaptureAround', |
137 | prefetch => { single_track => { cd => 'artist' } }, |
138 | order_by => 'me.cdid', |
139 | })->all]), |
140 | [ |
141 | [ |
142 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
143 | { single_track => [] } |
144 | ], |
145 | [ |
146 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
147 | { single_track => [] } |
148 | ], |
149 | [ |
150 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
151 | { single_track => [ |
152 | { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
153 | { cd => [ |
154 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
155 | { |
156 | artist => [ |
157 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 } |
158 | ] |
159 | } |
160 | ] } |
161 | ] } |
162 | ], |
163 | [ |
164 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
165 | { single_track => [ ] } |
166 | ], |
167 | ], |
168 | 'Simple 1:1 descend with classic prefetch pruning' |
169 | ); |
170 | |
171 | |
172 | cmp_structures( |
908aa1bb |
173 | [$schema->resultset ('CD')->search ({}, { |
174 | result_class => 'DBICTest::_IRCapture', |
175 | join => { single_track => { cd => 'artist' } }, |
176 | columns => [ |
177 | { 'year' => 'me.year' }, |
178 | { 'genreid' => 'me.genreid' }, |
179 | { 'single_track.cd.artist.artistid' => 'artist.artistid' }, |
180 | { 'title' => 'me.title' }, |
181 | { 'artist' => 'me.artist' }, |
182 | ], |
183 | order_by => 'me.cdid', |
184 | })->all], |
185 | [ |
186 | [ |
187 | { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
188 | { single_track => [ |
189 | undef, |
190 | { cd => [ |
191 | undef, |
192 | { |
193 | artist => [ |
194 | { artistid => undef } |
195 | ] |
196 | } |
197 | ] } |
198 | ] } |
199 | ], |
200 | [ |
201 | { artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
202 | { single_track => [ |
203 | undef, |
204 | { cd => [ |
205 | undef, |
206 | { |
207 | artist => [ |
208 | { artistid => undef } |
209 | ] |
210 | } |
211 | ] } |
212 | ] } |
213 | ], |
214 | [ |
215 | { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
216 | { single_track => [ |
217 | undef, |
218 | { cd => [ |
219 | undef, |
220 | { |
221 | artist => [ |
222 | { artistid => 1 } |
223 | ] |
224 | } |
225 | ] } |
226 | ] } |
227 | ], |
ce556881 |
228 | [ |
229 | { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
230 | { single_track => [ |
231 | undef, |
232 | { cd => [ |
233 | undef, |
234 | { |
235 | artist => [ |
236 | { artistid => undef } |
237 | ] |
238 | } |
239 | ] } |
240 | ] } |
241 | ], |
908aa1bb |
242 | ], |
ce556881 |
243 | 'Simple 1:1 descend with missing selectors legacy' |
908aa1bb |
244 | ); |
245 | |
ce556881 |
246 | cmp_structures( |
247 | [$schema->resultset ('CD')->search ({}, { |
248 | result_class => 'DBICTest::_IRCaptureAround', |
249 | join => { single_track => { cd => 'artist' } }, |
250 | columns => [ |
251 | { 'year' => 'me.year' }, |
252 | { 'genreid' => 'me.genreid' }, |
253 | { 'single_track.cd.artist.artistid' => 'artist.artistid' }, |
254 | { 'title' => 'me.title' }, |
255 | { 'artist' => 'me.artist' }, |
256 | ], |
257 | order_by => 'me.cdid', |
258 | })->all], |
259 | [ |
260 | [ |
261 | { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
262 | { single_track => [] } |
263 | ], |
264 | [ |
265 | { artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
266 | { single_track => [ ] } |
267 | ], |
268 | [ |
269 | { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
270 | { single_track => [ |
271 | undef, |
272 | { cd => [ |
273 | undef, |
274 | { |
275 | artist => [ |
276 | { artistid => 1 } |
277 | ] |
278 | } |
279 | ] } |
280 | ] } |
281 | ], |
282 | [ |
283 | { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
284 | { single_track => [] } |
285 | ], |
286 | ], |
287 | 'Simple 1:1 descend with missing selectors pruning' |
288 | ); |
289 | |
290 | cmp_structures( |
908aa1bb |
291 | ([$schema->resultset ('CD')->search ({}, { |
292 | result_class => 'DBICTest::_IRCapture', |
293 | prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ], |
294 | order_by => [qw/me.cdid tracks.trackid/], |
295 | })->all]), |
296 | [ |
297 | [ |
298 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
299 | { single_track => [ |
300 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
301 | { cd => [ |
302 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
303 | { |
304 | artist => [ |
305 | { artistid => undef, name => undef, charfield => undef, rank => undef }, |
306 | { cds => [ [ |
307 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
308 | { tracks => [ [ |
309 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
310 | ] ] }, |
311 | ]]}, |
312 | ], |
313 | }, |
314 | ] }, |
315 | ] }, |
316 | ], |
317 | [ |
318 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
319 | { single_track => [ |
320 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
321 | { cd => [ |
322 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
323 | { |
324 | artist => [ |
325 | { artistid => undef, name => undef, charfield => undef, rank => undef }, |
326 | { cds => [ [ |
327 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
328 | { tracks => [ [ |
329 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
330 | ] ] }, |
331 | ]]}, |
332 | ] |
333 | } |
334 | ] } |
335 | ] } |
336 | ], |
337 | [ |
338 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
339 | { single_track => [ |
340 | { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
341 | { cd => [ |
342 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
343 | { |
344 | artist => [ |
345 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
346 | { cds => [ |
347 | [ |
ce556881 |
348 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
349 | { tracks => [ |
350 | [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ], |
351 | ] }, |
352 | ], |
353 | [ |
354 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
355 | { tracks => [ |
356 | [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
357 | [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
358 | [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
359 | [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
360 | ]}, |
361 | ], |
362 | [ |
363 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
364 | { tracks => [ |
365 | [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ], |
366 | [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ], |
367 | ]}, |
368 | ], |
369 | [ |
370 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
371 | { tracks => [ |
372 | [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ], |
373 | [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ], |
374 | [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ], |
375 | ]}, |
376 | ], |
377 | ]}, |
378 | ] |
379 | } |
380 | ] } |
381 | ] } |
382 | ], |
383 | [ |
384 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
385 | { single_track => [ |
386 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
387 | { cd => [ |
388 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
389 | { |
390 | artist => [ |
391 | { artistid => undef, name => undef, charfield => undef, rank => undef }, |
392 | { cds => [ [ |
393 | { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef }, |
394 | { tracks => [ [ |
395 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
396 | ] ] }, |
397 | ]]}, |
398 | ] |
399 | } |
400 | ] } |
401 | ] } |
402 | ], |
403 | ], |
404 | 'Collapsing 1:1 ending in chained has_many with classic prefetch legacy' |
405 | ); |
406 | |
407 | cmp_structures( |
408 | ([$schema->resultset ('CD')->search ({}, { |
409 | result_class => 'DBICTest::_IRCaptureAround', |
410 | prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ], |
411 | order_by => [qw/me.cdid tracks.trackid/], |
412 | })->all]), |
413 | [ |
414 | [ |
415 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
416 | { single_track => [ ] }, |
417 | ], |
418 | [ |
419 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
420 | { single_track => [ ] }, |
421 | ], |
422 | [ |
423 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
424 | { single_track => [ |
425 | { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
426 | { cd => [ |
427 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
428 | { |
429 | artist => [ |
430 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
431 | { cds => [ |
432 | [ |
433 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
434 | { tracks => [ ] }, |
435 | ], |
436 | [ |
908aa1bb |
437 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
438 | { tracks => [ |
439 | [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
440 | [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
441 | [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
442 | [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ], |
443 | ]}, |
444 | ], |
445 | [ |
446 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
447 | { tracks => [ |
448 | [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ], |
449 | [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ], |
450 | ]}, |
451 | ], |
452 | [ |
453 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
454 | { tracks => [ |
455 | [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ], |
456 | [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ], |
457 | [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ], |
458 | ]}, |
459 | ], |
460 | ]}, |
461 | ] |
462 | } |
463 | ] } |
464 | ] } |
465 | ], |
ce556881 |
466 | [ |
467 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
468 | { single_track => [ ] }, |
469 | ], |
908aa1bb |
470 | ], |
ce556881 |
471 | 'Collapsing 1:1 ending in chained has_many with classic prefetch pruning' |
908aa1bb |
472 | ); |
473 | |
ce556881 |
474 | cmp_structures ( |
908aa1bb |
475 | ([$schema->resultset ('Artist')->search ({}, { |
476 | result_class => 'DBICTest::_IRCapture', |
477 | join => { cds => 'tracks' }, |
478 | '+columns' => [ |
479 | (map { "cds.$_" } $schema->source('CD')->columns), |
480 | (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns), |
481 | ], |
482 | order_by => [qw/cds.cdid tracks.trackid/], |
483 | })->all]), |
484 | [ |
485 | [ |
486 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
487 | { cds => [ |
488 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
489 | { tracks => [ |
490 | { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
491 | ]}, |
492 | ]}, |
493 | ], |
494 | [ |
495 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
496 | { cds => [ |
497 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
498 | { tracks => [ |
499 | { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
500 | ]}, |
501 | ]}, |
502 | ], |
503 | [ |
504 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
505 | { cds => [ |
506 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
507 | { tracks => [ |
508 | { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
509 | ]}, |
510 | ]}, |
511 | ], |
512 | [ |
513 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
514 | { cds => [ |
515 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
516 | { tracks => [ |
517 | { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
518 | ]}, |
519 | ]}, |
520 | ], |
521 | [ |
522 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
523 | { cds => [ |
524 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
525 | { tracks => [ |
526 | { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
527 | ]}, |
528 | ]}, |
529 | ], |
530 | [ |
531 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
532 | { cds => [ |
533 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
534 | { tracks => [ |
535 | { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
536 | ]}, |
537 | ]}, |
538 | ], |
539 | [ |
540 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
541 | { cds => [ |
542 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
543 | { tracks => [ |
544 | { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef }, |
545 | ]}, |
546 | ]}, |
547 | ], |
548 | [ |
549 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
550 | { cds => [ |
551 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
552 | { tracks => [ |
553 | { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef }, |
554 | ]}, |
555 | ]}, |
556 | ], |
557 | [ |
558 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
559 | { cds => [ |
560 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
561 | { tracks => [ |
562 | { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef }, |
563 | ]}, |
564 | ]}, |
565 | ], |
ce556881 |
566 | [ |
567 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
568 | { cds => [ |
569 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
570 | { tracks => [ |
571 | { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef }, |
572 | ]}, |
573 | ]}, |
574 | ], |
908aa1bb |
575 | ], |
ce556881 |
576 | 'Non-Collapsing chained has_many legacy' |
908aa1bb |
577 | ); |
578 | |
ce556881 |
579 | cmp_structures( |
580 | ([$schema->resultset ('Artist')->search ({}, { |
581 | result_class => 'DBICTest::_IRCaptureAround', |
582 | join => { cds => 'tracks' }, |
583 | '+columns' => [ |
584 | (map { "cds.$_" } $schema->source('CD')->columns), |
585 | (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns), |
586 | ], |
587 | order_by => [qw/cds.cdid tracks.trackid/], |
588 | })->all]), |
589 | [ |
590 | [ |
591 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
592 | { cds => [ |
593 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
594 | { tracks => [ |
595 | { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
596 | ]}, |
597 | ]}, |
598 | ], |
599 | [ |
600 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
601 | { cds => [ |
602 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
603 | { tracks => [ |
604 | { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
605 | ]}, |
606 | ]}, |
607 | ], |
608 | [ |
609 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
610 | { cds => [ |
611 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
612 | { tracks => [ |
613 | { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
614 | ]}, |
615 | ]}, |
616 | ], |
617 | [ |
618 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
619 | { cds => [ |
620 | { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" }, |
621 | { tracks => [ |
622 | { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef }, |
623 | ]}, |
624 | ]}, |
625 | ], |
626 | [ |
627 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
628 | { cds => [ |
629 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
630 | { tracks => [ |
631 | { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
632 | ]}, |
633 | ]}, |
634 | ], |
635 | [ |
636 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
637 | { cds => [ |
638 | { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" }, |
639 | { tracks => [ |
640 | { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef }, |
641 | ]}, |
642 | ]}, |
643 | ], |
644 | [ |
645 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
646 | { cds => [ |
647 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
648 | { tracks => [ |
649 | { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef }, |
650 | ]}, |
651 | ]}, |
652 | ], |
653 | [ |
654 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
655 | { cds => [ |
656 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
657 | { tracks => [ |
658 | { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef }, |
659 | ]}, |
660 | ]}, |
661 | ], |
662 | [ |
663 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
664 | { cds => [ |
665 | { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" }, |
666 | { tracks => [ |
667 | { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef }, |
668 | ]}, |
669 | ]}, |
670 | ], |
671 | [ |
672 | { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }, |
673 | { cds => [ |
674 | { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" }, |
675 | { tracks => [ ] }, |
676 | ]}, |
677 | ], |
678 | ], |
679 | 'Non-Collapsing chained has_many pruning' |
680 | ); |
681 | |
682 | sub cmp_structures { |
683 | my ($left, $right, $msg) = @_; |
684 | |
685 | local $TODO = "Pruning test won't work on pre-rewrite DBIC" |
686 | if ($msg||'') =~ /pruning$/ and ! $new_collapser_version; |
687 | |
688 | local $Test::Builder::Level = $Test::Builder::Level + 1; |
689 | is_deeply($left, $right, $msg||()); |
690 | } |
691 | |
908aa1bb |
692 | done_testing; |