10 my $schema = DBICTest->init_schema(no_populate => 1);
12 $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
13 title => 'Magnetic Fields',
15 genre => { name => 'electro' },
24 $schema->resultset('CD')->create({
27 artist => { name => 'JMJ' },
28 genre => { name => 'electro' },
39 artist => { name => 'JMJ' },
41 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
47 $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" });
49 $schema->resultset('Artist')->create({ name => "${_}_cdless" })
52 # subs at the end of the test refer to this
56 # run entire test twice - with and without "native inflator"
57 INFTYPE: for ('', '(native inflator)') {
59 $native_inflator = $_;
62 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
63 prefetch => { single_track => { cd => 'artist' } },
64 order_by => 'me.cdid',
68 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
69 { single_track => code(sub { null_branch ( \@_, [
70 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
71 { cd => code(sub { null_branch ( \@_, [
72 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
74 artist => code(sub { null_branch ( \@_, [
75 { artistid => undef, name => undef, charfield => undef, rank => undef }
82 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
83 { single_track => code(sub { null_branch ( \@_, [
84 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
85 { cd => code(sub { null_branch ( \@_, [
86 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
88 artist => code(sub { null_branch ( \@_, [
89 { artistid => undef, name => undef, charfield => undef, rank => undef }
96 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
98 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
100 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
103 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
110 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
111 { single_track => code(sub { null_branch ( \@_, [
112 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
113 { cd => code(sub { null_branch ( \@_, [
114 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
116 artist => code(sub { null_branch ( \@_, [
117 { artistid => undef, name => undef, charfield => undef, rank => undef }
124 "Simple 1:1 descend with classic prefetch $native_inflator"
128 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
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 => code(sub { null_branch ( \@_, [
148 { artistid => undef }
155 { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
156 { single_track => code(sub { null_branch ( \@_, [
162 { artistid => undef }
169 { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
183 { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
184 { single_track => code(sub { null_branch ( \@_, [
190 { artistid => undef }
197 "Simple 1:1 descend with missing selectors $native_inflator",
201 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
202 prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
203 order_by => [qw/me.cdid tracks.trackid/],
207 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
208 { single_track => code(sub { null_collapsed_branch ( \@_, [
209 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
211 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
214 { artistid => undef, name => undef, charfield => undef, rank => undef },
215 { cds => code(sub { null_collapsed_branch ( \@_, [ [
216 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
217 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
218 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
227 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
228 { single_track => code(sub { null_collapsed_branch ( \@_, [
229 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
231 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
234 { artistid => undef, name => undef, charfield => undef, rank => undef },
235 { cds => code(sub { null_collapsed_branch ( \@_, [ [
236 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
237 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
238 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
247 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
249 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
251 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
254 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
257 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
258 { tracks => code(sub { null_collapsed_branch ( \@_, [
259 [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
263 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
265 [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
266 [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
267 [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
268 [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
272 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
274 [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
275 [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
279 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
281 [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
282 [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
283 [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
293 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
294 { single_track => code(sub { null_collapsed_branch ( \@_, [
295 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
297 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
300 { artistid => undef, name => undef, charfield => undef, rank => undef },
301 { cds => code(sub { null_collapsed_branch ( \@_, [ [
302 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
303 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
304 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
313 "Collapsing 1:1 ending in chained has_many with classic prefetch $native_inflator",
317 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
318 join => { cds => 'tracks' },
320 (map { "cds.$_" } $schema->source('CD')->columns),
321 (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns),
323 order_by => [qw/cds.cdid tracks.trackid me.name/],
327 { artistid => 3, name => 'A_cdless', charfield => undef, rank => 13 },
328 { cds => code(sub { null_branch ( \@_, [
329 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
330 { tracks => code(sub { null_branch ( \@_, [
331 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
336 { artistid => 2, name => 'Z_cdless', charfield => undef, rank => 13 },
337 { cds => code(sub { null_branch ( \@_, [
338 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
339 { tracks => code(sub { null_branch ( \@_, [
340 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
345 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
347 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
349 { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef },
354 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
356 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
358 { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
363 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
365 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
367 { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
372 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
374 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
376 { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
381 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
383 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
385 { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
390 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
392 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
394 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
399 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
401 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
403 { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
408 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
410 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
412 { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
417 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
419 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
421 { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
426 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
428 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
429 { tracks => code(sub { null_branch ( \@_, [
430 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
435 "Non-Collapsing chained has_many $native_inflator",
439 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
442 columns => [qw( cds.title cds.artist )],
443 order_by => [qw( me.name cds.title )],
448 { cds => code(sub { null_collapsed_branch ( \@_, [
449 [ { artist => undef, title => undef } ]
455 [ { artist => 1, title => "Equinoxe" } ],
456 [ { artist => 1, title => "Magnetic Fields" } ],
457 [ { artist => 1, title => "Oxygene" } ],
458 [ { artist => 1, title => "fuzzy_1" } ],
463 { cds => code(sub { null_collapsed_branch ( \@_, [
464 [ { artist => undef, title => undef } ]
468 "Expected output of collapsing 1:M with empty root selection $native_inflator",
475 $native_inflator ? undef : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
478 sub null_collapsed_branch {
481 $native_inflator ? [] : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
486 package DBICTest::_IRCapture;
487 sub inflate_result { [@_[2,3]] };
492 $rs->result_class('DBICTest::_IRCapture');
493 die 'eeeeek - preprocessed $rs' if defined $rs->{_result_inflator}{is_core_row};
494 $rs->{_result_inflator}{is_core_row} = 1 if $native_inflator;
499 my ($left, $right, $msg) = @_;
501 local $Test::Builder::Level = $Test::Builder::Level + 1;
502 cmp_deeply($left, $right, $msg||()) or next INFTYPE;