1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
12 my $schema = DBICTest->init_schema(no_populate => 1);
14 $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
15 title => 'Magnetic Fields',
17 genre => { name => 'electro' },
26 $schema->resultset('CD')->create({
29 artist => { name => 'JMJ' },
30 genre => { name => 'electro' },
41 artist => { name => 'JMJ' },
43 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
49 $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" });
51 $schema->resultset('Artist')->create({ name => "${_}_cdless" })
54 # subs at the end of the test refer to this
58 # run entire test twice - with and without "native inflator"
59 INFTYPE: for ('', '(native inflator)') {
61 $native_inflator = $_;
64 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
65 prefetch => { single_track => { cd => 'artist' } },
66 order_by => 'me.cdid',
70 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
71 { single_track => code(sub { null_branch ( \@_, [
72 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
73 { cd => code(sub { null_branch ( \@_, [
74 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
76 artist => code(sub { null_branch ( \@_, [
77 { artistid => undef, name => undef, charfield => undef, rank => undef }
84 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
85 { single_track => code(sub { null_branch ( \@_, [
86 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
87 { cd => code(sub { null_branch ( \@_, [
88 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
90 artist => code(sub { null_branch ( \@_, [
91 { artistid => undef, name => undef, charfield => undef, rank => undef }
98 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
100 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
102 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
105 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
112 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
113 { single_track => code(sub { null_branch ( \@_, [
114 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
115 { cd => code(sub { null_branch ( \@_, [
116 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
118 artist => code(sub { null_branch ( \@_, [
119 { artistid => undef, name => undef, charfield => undef, rank => undef }
126 "Simple 1:1 descend with classic prefetch $native_inflator"
130 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
131 join => { single_track => { cd => 'artist' } },
133 { 'year' => 'me.year' },
134 { 'genreid' => 'me.genreid' },
135 { 'single_track.cd.artist.artistid' => 'artist.artistid' },
136 { 'title' => 'me.title' },
137 { 'artist' => 'me.artist' },
139 order_by => 'me.cdid',
143 { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
144 { single_track => code(sub { null_branch ( \@_, [
150 { artistid => undef }
157 { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
158 { single_track => code(sub { null_branch ( \@_, [
164 { artistid => undef }
171 { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
185 { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
186 { single_track => code(sub { null_branch ( \@_, [
192 { artistid => undef }
199 "Simple 1:1 descend with missing selectors $native_inflator",
203 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
204 prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
205 order_by => [qw/me.cdid tracks.trackid/],
209 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
210 { single_track => code(sub { null_collapsed_branch ( \@_, [
211 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
213 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
216 { artistid => undef, name => undef, charfield => undef, rank => undef },
217 { cds => code(sub { null_collapsed_branch ( \@_, [ [
218 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
219 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
220 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
229 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
230 { single_track => code(sub { null_collapsed_branch ( \@_, [
231 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
233 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
236 { artistid => undef, name => undef, charfield => undef, rank => undef },
237 { cds => code(sub { null_collapsed_branch ( \@_, [ [
238 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
239 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
240 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
249 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
251 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
253 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
256 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
259 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
260 { tracks => code(sub { null_collapsed_branch ( \@_, [
261 [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
265 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
267 [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
268 [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
269 [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
270 [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
274 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
276 [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
277 [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
281 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
283 [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
284 [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
285 [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
295 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
296 { single_track => code(sub { null_collapsed_branch ( \@_, [
297 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
299 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
302 { artistid => undef, name => undef, charfield => undef, rank => undef },
303 { cds => code(sub { null_collapsed_branch ( \@_, [ [
304 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
305 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
306 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
315 "Collapsing 1:1 ending in chained has_many with classic prefetch $native_inflator",
319 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
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 me.name/],
329 { artistid => 3, name => 'A_cdless', charfield => undef, rank => 13 },
330 { cds => code(sub { null_branch ( \@_, [
331 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
332 { tracks => code(sub { null_branch ( \@_, [
333 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
338 { artistid => 2, name => 'Z_cdless', charfield => undef, rank => 13 },
339 { cds => code(sub { null_branch ( \@_, [
340 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
341 { tracks => code(sub { null_branch ( \@_, [
342 { trackid => undef, title => undef, position => undef, cd => undef, 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 => 1, title => 'm1', position => 1, 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 => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
365 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
367 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
369 { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
374 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
376 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
378 { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
383 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
385 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
387 { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
392 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
394 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
396 { trackid => 6, title => 'o1', position => 1, cd => 2, 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 => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
410 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
412 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
414 { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
419 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
421 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
423 { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
428 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
430 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
431 { tracks => code(sub { null_branch ( \@_, [
432 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
437 "Non-Collapsing chained has_many $native_inflator",
441 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
444 columns => [qw( cds.title cds.artist )],
445 order_by => [qw( me.name cds.title )],
450 { cds => code(sub { null_collapsed_branch ( \@_, [
451 [ { artist => undef, title => undef } ]
457 [ { artist => 1, title => "Equinoxe" } ],
458 [ { artist => 1, title => "Magnetic Fields" } ],
459 [ { artist => 1, title => "Oxygene" } ],
460 [ { artist => 1, title => "fuzzy_1" } ],
465 { cds => code(sub { null_collapsed_branch ( \@_, [
466 [ { artist => undef, title => undef } ]
470 "Expected output of collapsing 1:M with empty root selection $native_inflator",
477 $native_inflator ? undef : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
480 sub null_collapsed_branch {
483 $native_inflator ? [] : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
488 package DBICTest::_IRCapture;
489 sub inflate_result { [@_[2,3]] };
494 $rs->result_class('DBICTest::_IRCapture');
495 die 'eeeeek - preprocessed $rs' if defined $rs->{_result_inflator}{is_core_row};
496 $rs->{_result_inflator}{is_core_row} = 1 if $native_inflator;
501 my ($left, $right, $msg) = @_;
503 local $Test::Builder::Level = $Test::Builder::Level + 1;
504 cmp_deeply($left, $right, $msg||()) or next INFTYPE;
508 package DBICTest::_DoubleResult;
512 return map { DBIx::Class::ResultClass::HashRefInflator->inflate_result(@_) } (1,2);
516 my $oxygene_rs = $schema->resultset('CD')->search({ 'me.title' => 'Oxygene' });
519 [ $oxygene_rs->search({}, { result_class => 'DBICTest::_DoubleResult' })->all ],
520 [ ({ $oxygene_rs->single->get_columns }) x 2 ],
524 [ $oxygene_rs->search({}, {
525 result_class => 'DBICTest::_DoubleResult', prefetch => [qw(artist tracks)],
526 order_by => [qw(me.cdid tracks.title)],
528 [ (@{$oxygene_rs->search({}, {
529 prefetch=> [qw(artist tracks)],
530 order_by => [qw(me.cdid tracks.title)],