Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
ce556881 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
52864fbd |
7 | use Test::Deep; |
c0329273 |
8 | |
ce556881 |
9 | use DBICTest; |
10 | |
11 | # More tests like this in t/prefetch/manual.t |
12 | |
13 | my $schema = DBICTest->init_schema(no_populate => 1, quote_names => 1); |
14 | $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{ |
15 | title => 'Magnetic Fields', |
16 | year => 1981, |
17 | genre => { name => 'electro' }, |
18 | tracks => [ |
19 | { title => 'm1' }, |
20 | { title => 'm2' }, |
21 | { title => 'm3' }, |
22 | { title => 'm4' }, |
23 | ], |
24 | } ] }); |
25 | |
26 | |
27 | $schema->resultset('CD')->create({ |
28 | title => 'Equinoxe', |
29 | year => 1978, |
30 | artist => { name => 'JMJ' }, |
31 | genre => { name => 'electro' }, |
32 | tracks => [ |
33 | { title => 'e1' }, |
34 | { title => 'e2' }, |
35 | { title => 'e3' }, |
36 | ], |
37 | single_track => { |
38 | title => 'o1', |
39 | cd => { |
40 | title => 'Oxygene', |
41 | year => 1976, |
42 | artist => { name => 'JMJ' }, |
40471d46 |
43 | artwork => {}, |
ce556881 |
44 | tracks => [ |
45 | { title => 'o2', position => 2}, # the position should not be needed here, bug in MC |
46 | ], |
47 | }, |
48 | }, |
49 | }); |
50 | |
51 | for (1,2) { |
52 | $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_$_" }); |
53 | } |
54 | |
52864fbd |
55 | { |
56 | package DBICTest::HRI::Subclass; |
57 | use base 'DBIx::Class::ResultClass::HashRefInflator'; |
58 | } |
59 | |
60 | { |
61 | package DBICTest::HRI::Around; |
62 | use base 'DBIx::Class::ResultClass::HashRefInflator'; |
63 | |
64 | sub inflate_result { shift->next::method(@_) } |
65 | } |
ce556881 |
66 | |
52864fbd |
67 | for my $rs ( |
68 | $schema->resultset('CD')->search_rs({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }), |
69 | $schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Subclass' }), |
70 | $schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Around' }), |
71 | ) { |
72 | |
73 | cmp_deeply |
74 | [ $rs->search({}, { |
ce556881 |
75 | columns => { |
76 | year => 'me.year', |
77 | 'single_track.cd.artist.name' => 'artist.name', |
78 | }, |
79 | join => { single_track => { cd => 'artist' } }, |
80 | order_by => [qw/me.cdid artist.artistid/], |
52864fbd |
81 | })->all ], |
ce556881 |
82 | [ |
3d3e99db |
83 | { year => 1981, single_track => undef }, |
84 | { year => 1976, single_track => undef }, |
85 | { year => 1978, single_track => { |
86 | cd => { |
87 | artist => { name => "JMJ" } |
ce556881 |
88 | }, |
3d3e99db |
89 | }}, |
90 | { year => 1977, single_track => undef }, |
91 | { year => 1977, single_track => undef }, |
92 | |
ce556881 |
93 | ], |
52864fbd |
94 | 'plain 1:1 descending chain ' . $rs->result_class |
ce556881 |
95 | ; |
96 | |
52864fbd |
97 | cmp_deeply |
98 | [ $rs->search({}, { |
ce556881 |
99 | columns => { |
100 | 'artist' => 'me.artist', |
101 | 'title' => 'me.title', |
102 | 'year' => 'me.year', |
103 | 'single_track.cd.artist.artistid' => 'artist.artistid', |
104 | 'single_track.cd.artist.cds.cdid' => 'cds.cdid', |
105 | 'single_track.cd.artist.cds.tracks.title' => 'tracks.title', |
106 | }, |
107 | join => { single_track => { cd => { artist => { cds => 'tracks' } } } }, |
108 | order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/], |
52864fbd |
109 | })->all ], |
ce556881 |
110 | [ |
111 | { |
3d3e99db |
112 | artist => 1, title => "Magnetic Fields", year => 1981, single_track => undef, |
ce556881 |
113 | }, |
114 | { |
3d3e99db |
115 | artist => 1, title => "Oxygene", year => 1976, single_track => undef, |
ce556881 |
116 | }, |
117 | { |
3d3e99db |
118 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
119 | cd => { |
120 | artist => { |
3d3e99db |
121 | artistid => 1, cds => { |
122 | cdid => 1, tracks => { |
ce556881 |
123 | title => "m1" |
124 | } |
125 | } |
126 | } |
127 | } |
128 | }, |
ce556881 |
129 | }, |
130 | { |
3d3e99db |
131 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
132 | cd => { |
133 | artist => { |
3d3e99db |
134 | artistid => 1, cds => { |
135 | cdid => 1, tracks => { |
ce556881 |
136 | title => "m2" |
137 | } |
138 | } |
139 | } |
140 | } |
141 | }, |
ce556881 |
142 | }, |
143 | { |
3d3e99db |
144 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
145 | cd => { |
146 | artist => { |
3d3e99db |
147 | artistid => 1, cds => { |
148 | cdid => 1, tracks => { |
ce556881 |
149 | title => "m3" |
150 | } |
151 | } |
152 | } |
153 | } |
154 | }, |
ce556881 |
155 | }, |
156 | { |
3d3e99db |
157 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
158 | cd => { |
159 | artist => { |
3d3e99db |
160 | artistid => 1, cds => { |
161 | cdid => 1, tracks => { |
ce556881 |
162 | title => "m4" |
163 | } |
164 | } |
165 | } |
166 | } |
167 | }, |
ce556881 |
168 | }, |
169 | { |
3d3e99db |
170 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
171 | cd => { |
172 | artist => { |
3d3e99db |
173 | artistid => 1, cds => { |
174 | cdid => 2, tracks => { |
ce556881 |
175 | title => "o2" |
176 | } |
177 | } |
178 | } |
179 | } |
180 | }, |
ce556881 |
181 | }, |
182 | { |
3d3e99db |
183 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
184 | cd => { |
185 | artist => { |
3d3e99db |
186 | artistid => 1, cds => { |
187 | cdid => 2, tracks => { |
ce556881 |
188 | title => "o1" |
189 | } |
190 | } |
191 | } |
192 | } |
193 | }, |
ce556881 |
194 | }, |
195 | { |
3d3e99db |
196 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
197 | cd => { |
198 | artist => { |
3d3e99db |
199 | artistid => 1, cds => { |
200 | cdid => 3, tracks => { |
ce556881 |
201 | title => "e1" |
202 | } |
203 | } |
204 | } |
205 | } |
206 | }, |
ce556881 |
207 | }, |
208 | { |
3d3e99db |
209 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
210 | cd => { |
211 | artist => { |
3d3e99db |
212 | artistid => 1, cds => { |
213 | cdid => 3, tracks => { |
ce556881 |
214 | title => "e2" |
215 | } |
216 | } |
217 | } |
218 | } |
219 | }, |
ce556881 |
220 | }, |
221 | { |
3d3e99db |
222 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
223 | cd => { |
224 | artist => { |
3d3e99db |
225 | artistid => 1, cds => { |
226 | cdid => 3, tracks => { |
ce556881 |
227 | title => "e3" |
228 | } |
229 | } |
230 | } |
231 | } |
232 | }, |
ce556881 |
233 | }, |
234 | { |
3d3e99db |
235 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
236 | cd => { |
237 | artist => { |
3d3e99db |
238 | artistid => 1, cds => { |
239 | cdid => 4, tracks => undef |
ce556881 |
240 | } |
241 | } |
242 | } |
243 | }, |
ce556881 |
244 | }, |
245 | { |
3d3e99db |
246 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
247 | cd => { |
248 | artist => { |
3d3e99db |
249 | artistid => 1, cds => { |
250 | cdid => 5, tracks => undef |
ce556881 |
251 | } |
252 | } |
253 | } |
254 | }, |
ce556881 |
255 | }, |
256 | { |
3d3e99db |
257 | artist => 1, title => "fuzzy_1", year => 1977, single_track => undef, |
ce556881 |
258 | }, |
259 | { |
3d3e99db |
260 | artist => 1, title => "fuzzy_2", year => 1977, single_track => undef, |
ce556881 |
261 | } |
262 | ], |
52864fbd |
263 | 'non-collapsing 1:1:1:M:M chain ' . $rs->result_class, |
ce556881 |
264 | ; |
265 | |
52864fbd |
266 | cmp_deeply |
267 | [ $rs->search({}, { |
ce556881 |
268 | columns => { |
269 | 'artist' => 'me.artist', |
270 | 'title' => 'me.title', |
271 | 'year' => 'me.year', |
272 | 'single_track.cd.artist.artistid' => 'artist.artistid', |
273 | 'single_track.cd.artist.cds.cdid' => 'cds.cdid', |
274 | 'single_track.cd.artist.cds.tracks.title' => 'tracks.title', |
275 | }, |
276 | join => { single_track => { cd => { artist => { cds => 'tracks' } } } }, |
277 | order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/], |
859b7922 |
278 | collapse => 1, |
52864fbd |
279 | })->all ], |
ce556881 |
280 | [ |
281 | { |
3d3e99db |
282 | artist => 1, title => "Magnetic Fields", year => 1981, single_track => undef, |
ce556881 |
283 | }, |
284 | { |
3d3e99db |
285 | artist => 1, title => "Oxygene", year => 1976, single_track => undef, |
ce556881 |
286 | }, |
287 | { |
3d3e99db |
288 | artist => 1, title => "Equinoxe", year => 1978, single_track => { |
ce556881 |
289 | cd => { |
290 | artist => { |
3d3e99db |
291 | artistid => 1, cds => [ |
ce556881 |
292 | { |
3d3e99db |
293 | cdid => 1, tracks => [ |
294 | { title => "m1" }, |
295 | { title => "m2" }, |
296 | { title => "m3" }, |
297 | { title => "m4" }, |
ce556881 |
298 | ] |
299 | }, |
300 | { |
3d3e99db |
301 | cdid => 2, tracks => [ |
302 | { title => "o2" }, |
303 | { title => "o1" }, |
ce556881 |
304 | ] |
305 | }, |
306 | { |
3d3e99db |
307 | cdid => 3, tracks => [ |
308 | { title => "e1" }, |
309 | { title => "e2" }, |
310 | { title => "e3" }, |
ce556881 |
311 | ] |
312 | }, |
313 | { |
3d3e99db |
314 | cdid => 4, tracks => [], |
ce556881 |
315 | }, |
316 | { |
3d3e99db |
317 | cdid => 5, tracks => [], |
ce556881 |
318 | } |
319 | ] |
320 | } |
321 | } |
322 | }, |
ce556881 |
323 | }, |
324 | { |
3d3e99db |
325 | artist => 1, title => "fuzzy_1", year => 1977, single_track => undef, |
ce556881 |
326 | }, |
327 | { |
3d3e99db |
328 | artist => 1, title => "fuzzy_2", year => 1977, single_track => undef, |
ce556881 |
329 | } |
330 | ], |
52864fbd |
331 | 'collapsing 1:1:1:M:M chain ' . $rs->result_class, |
ce556881 |
332 | ; |
333 | |
40471d46 |
334 | cmp_deeply |
335 | [ $rs->search_rs ( |
336 | { |
337 | 'tracks.title' => 'e2', |
338 | 'cds.title' => 'Oxygene', |
339 | }, |
340 | { |
341 | collapse => 1, |
342 | join => [ |
343 | 'tracks', |
344 | { single_track => { cd => 'mandatory_artwork' } }, |
345 | { artist => { cds => 'mandatory_artwork'} }, |
346 | ], |
347 | columns => { |
348 | cdid => 'cdid', |
349 | 'single_track.cd.mandatory_artwork.cd_id' => 'mandatory_artwork.cd_id', |
350 | 'artist.cds.mandatory_artwork.cd_id' => 'mandatory_artwork_2.cd_id', |
351 | }, |
352 | }, |
353 | )->all ], |
354 | [ |
355 | { |
356 | cdid => 3, |
357 | single_track => { |
358 | cd => { |
359 | mandatory_artwork => { cd_id => 2 }, |
360 | }, |
361 | }, |
362 | artist => { |
363 | cds => [ |
364 | { mandatory_artwork => { cd_id => 2 } } |
365 | ] |
366 | }, |
367 | }, |
368 | ], |
369 | ; |
370 | |
52864fbd |
371 | } |
372 | |
ce556881 |
373 | done_testing; |