9 my $schema = DBICTest->init_schema(no_populate => 1);
11 $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
12 title => 'Magnetic Fields',
14 genre => { name => 'electro' },
23 $schema->resultset('CD')->create({
26 artist => { name => 'JMJ' },
27 genre => { name => 'electro' },
38 artist => { name => 'JMJ' },
40 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
46 $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" });
49 package DBICTest::_IRCapture;
50 sub inflate_result { [@_[2,3]] };
54 package DBICTest::_IRCaptureAround;
55 use base 'DBIx::Class::Row';
56 sub inflate_result { [@_[2,3]] };
60 ([$schema->resultset ('CD')->search ({}, {
61 result_class => 'DBICTest::_IRCapture',
62 prefetch => { single_track => { cd => 'artist' } },
63 order_by => 'me.cdid',
67 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
68 { single_track => bless( [
69 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
71 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
74 { artistid => undef, name => undef, charfield => undef, rank => undef }
75 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
77 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
78 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
81 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
82 { single_track => bless( [
83 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
85 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
88 { artistid => undef, name => undef, charfield => undef, rank => undef }
89 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
91 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
92 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
95 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
97 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
99 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
102 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
109 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
110 { single_track => bless( [
111 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
113 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
116 { artistid => undef, name => undef, charfield => undef, rank => undef }
117 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
119 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
120 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
123 'Simple 1:1 descend with classic prefetch'
127 [$schema->resultset ('CD')->search ({}, {
128 result_class => 'DBICTest::_IRCapture',
129 join => { single_track => { cd => 'artist' } },
131 { 'year' => 'me.year' },
132 { 'genreid' => 'me.genreid' },
133 { 'single_track.cd.artist.artistid' => 'artist.artistid' },
134 { 'title' => 'me.title' },
135 { 'artist' => 'me.artist' },
137 order_by => 'me.cdid',
141 { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
142 { single_track => bless( [
148 { artistid => undef }
152 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
155 { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
156 { single_track => bless( [
162 { artistid => undef }
166 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
169 { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
183 { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
184 { single_track => bless( [
190 { artistid => undef }
194 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
197 'Simple 1:1 descend with missing selectors'
201 ([$schema->resultset ('CD')->search ({}, {
202 result_class => 'DBICTest::_IRCapture',
203 prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
204 order_by => [qw/me.cdid tracks.trackid/],
208 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
209 { single_track => bless( [
210 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
212 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
215 { artistid => undef, name => undef, charfield => undef, rank => undef },
217 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
218 { tracks => bless( [ [
219 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
220 ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
221 ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
225 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
228 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
229 { single_track => bless( [
230 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
232 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
235 { artistid => undef, name => undef, charfield => undef, rank => undef },
237 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
238 { tracks => bless( [ [
239 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
240 ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
241 ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
245 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
248 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
250 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
252 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
255 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
258 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
260 [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
261 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
264 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
266 [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
267 [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
268 [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
269 [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
273 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
275 [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
276 [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
280 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
282 [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
283 [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
284 [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
294 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
295 { single_track => bless( [
296 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
298 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
301 { artistid => undef, name => undef, charfield => undef, rank => undef },
303 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
304 { tracks => bless( [ [
305 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
306 ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
307 ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
311 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
314 'Collapsing 1:1 ending in chained has_many with classic prefetch'
318 ([$schema->resultset ('Artist')->search ({}, {
319 result_class => 'DBICTest::_IRCapture',
320 join => { cds => 'tracks' },
322 (map { "cds.$_" } $schema->source('CD')->columns),
323 (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns),
325 order_by => [qw/cds.cdid tracks.trackid/],
329 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
331 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
333 { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef },
338 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
340 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
342 { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
347 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
349 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
351 { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
356 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
358 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
360 { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
365 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
367 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
369 { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
374 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
376 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
378 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
383 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
385 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
387 { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
392 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
394 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
396 { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
401 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
403 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
405 { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
410 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
412 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
414 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
415 ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
419 'Non-Collapsing chained has_many'
423 my ($left, $right, $msg) = @_;
425 local $Test::Builder::Level = $Test::Builder::Level + 1;
426 cmp_deeply($left, $right, $msg||());