8 my $schema = DBICTest->init_schema(no_populate => 1);
10 $schema->resultset('CD')->create({
13 artist => { name => 'JMJ' },
14 genre => { name => 'electro' },
29 title => 'Magnetic Fields',
31 genre => { name => 'electro' },
42 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
49 package DBICTest::_IRCapture;
50 sub inflate_result { [@_[2,3]] };
54 ([$schema->resultset ('CD')->search ({}, {
55 result_class => 'DBICTest::_IRCapture',
56 prefetch => { single_track => { cd => 'artist' } },
57 order_by => 'me.cdid',
61 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
63 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
65 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
68 { artistid => undef, name => undef, charfield => undef, rank => undef }
75 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
77 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
79 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
82 { artistid => undef, name => undef, charfield => undef, rank => undef }
89 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
91 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
93 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
96 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
103 'Simple 1:1 descend with classic prefetch ok'
107 [$schema->resultset ('CD')->search ({}, {
108 result_class => 'DBICTest::_IRCapture',
109 join => { single_track => { cd => 'artist' } },
111 { 'year' => 'me.year' },
112 { 'genreid' => 'me.genreid' },
113 { 'single_track.cd.artist.artistid' => 'artist.artistid' },
114 { 'title' => 'me.title' },
115 { 'artist' => 'me.artist' },
117 order_by => 'me.cdid',
121 { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
128 { artistid => undef }
135 { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
142 { artistid => undef }
149 { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
163 'Simple 1:1 descend with missing selectors ok'
167 ([$schema->resultset ('CD')->search ({}, {
168 result_class => 'DBICTest::_IRCapture',
169 prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
170 order_by => [qw/me.cdid tracks.trackid/],
174 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
176 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
178 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
181 { artistid => undef, name => undef, charfield => undef, rank => undef },
183 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
185 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
194 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
196 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
198 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
201 { artistid => undef, name => undef, charfield => undef, rank => undef },
203 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
205 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
214 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
216 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
218 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
221 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
224 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
226 [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
227 [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
228 [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
229 [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
233 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
235 [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
236 [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
240 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
242 [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
243 [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
244 [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
254 'Collapsing 1:1 ending in chained has_many with classic prefetch ok'
258 ([$schema->resultset ('Artist')->search ({}, {
259 result_class => 'DBICTest::_IRCapture',
260 join => { cds => 'tracks' },
262 (map { "cds.$_" } $schema->source('CD')->columns),
263 (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns),
265 order_by => [qw/cds.cdid tracks.trackid/],
269 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
271 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
273 { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef },
278 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
280 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
282 { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
287 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
289 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
291 { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
296 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
298 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
300 { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
305 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
307 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
309 { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
314 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
316 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
318 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
323 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
325 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
327 { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
332 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
334 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
336 { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
341 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
343 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
345 { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
350 'Non-Collapsing chained has_many ok'