8 my $schema = DBICTest->init_schema(no_populate => 1);
10 $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
11 title => 'Magnetic Fields',
13 genre => { name => 'electro' },
22 $schema->resultset('CD')->create({
25 artist => { name => 'JMJ' },
26 genre => { name => 'electro' },
37 artist => { name => 'JMJ' },
39 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
46 package DBICTest::_IRCapture;
47 sub inflate_result { [@_[2,3]] };
51 ([$schema->resultset ('CD')->search ({}, {
52 result_class => 'DBICTest::_IRCapture',
53 prefetch => { single_track => { cd => 'artist' } },
54 order_by => 'me.cdid',
58 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
60 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
62 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
65 { artistid => undef, name => undef, charfield => undef, rank => undef }
72 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
74 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
76 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
79 { artistid => undef, name => undef, charfield => undef, rank => undef }
86 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
88 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
90 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
93 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
100 'Simple 1:1 descend with classic prefetch ok'
104 [$schema->resultset ('CD')->search ({}, {
105 result_class => 'DBICTest::_IRCapture',
106 join => { single_track => { cd => 'artist' } },
108 { 'year' => 'me.year' },
109 { 'genreid' => 'me.genreid' },
110 { 'single_track.cd.artist.artistid' => 'artist.artistid' },
111 { 'title' => 'me.title' },
112 { 'artist' => 'me.artist' },
114 order_by => 'me.cdid',
118 { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
125 { artistid => undef }
132 { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
139 { artistid => undef }
146 { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
160 'Simple 1:1 descend with missing selectors ok'
164 ([$schema->resultset ('CD')->search ({}, {
165 result_class => 'DBICTest::_IRCapture',
166 prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
167 order_by => [qw/me.cdid tracks.trackid/],
171 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
173 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
175 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
178 { artistid => undef, name => undef, charfield => undef, rank => undef },
180 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
182 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
191 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
193 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
195 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
198 { artistid => undef, name => undef, charfield => undef, rank => undef },
200 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
202 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
211 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
213 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
215 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
218 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
221 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
223 [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
224 [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
225 [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
226 [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
230 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
232 [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
233 [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
237 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
239 [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
240 [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
241 [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
251 'Collapsing 1:1 ending in chained has_many with classic prefetch ok'
255 ([$schema->resultset ('Artist')->search ({}, {
256 result_class => 'DBICTest::_IRCapture',
257 join => { cds => 'tracks' },
259 (map { "cds.$_" } $schema->source('CD')->columns),
260 (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns),
262 order_by => [qw/cds.cdid tracks.trackid/],
266 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
268 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
270 { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef },
275 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
277 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
279 { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
284 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
286 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
288 { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
293 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
295 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
297 { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
302 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
304 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
306 { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
311 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
313 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
315 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
320 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
322 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
324 { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
329 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
331 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
333 { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
338 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
340 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
342 { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
347 'Non-Collapsing chained has_many ok'