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' },
44 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
50 $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" });
52 $schema->resultset('Artist')->create({ name => "${_}_cdless" })
55 # subs at the end of the test refer to this
59 # run entire test twice - with and without "native inflator"
60 INFTYPE: for ('', '(native inflator)') {
62 $native_inflator = $_;
65 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
66 prefetch => { single_track => { cd => 'artist' } },
67 order_by => 'me.cdid',
71 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
72 { single_track => code(sub { null_branch ( \@_, [
73 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
74 { cd => code(sub { null_branch ( \@_, [
75 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
77 artist => code(sub { null_branch ( \@_, [
78 { artistid => undef, name => undef, charfield => undef, rank => undef }
85 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
86 { single_track => code(sub { null_branch ( \@_, [
87 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
88 { cd => code(sub { null_branch ( \@_, [
89 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
91 artist => code(sub { null_branch ( \@_, [
92 { artistid => undef, name => undef, charfield => undef, rank => undef }
99 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
101 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
103 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
106 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
113 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
114 { single_track => code(sub { null_branch ( \@_, [
115 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
116 { cd => code(sub { null_branch ( \@_, [
117 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
119 artist => code(sub { null_branch ( \@_, [
120 { artistid => undef, name => undef, charfield => undef, rank => undef }
127 "Simple 1:1 descend with classic prefetch $native_inflator"
131 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
132 join => { single_track => { cd => 'artist' } },
134 { 'year' => 'me.year' },
135 { 'genreid' => 'me.genreid' },
136 { 'single_track.cd.artist.artistid' => 'artist.artistid' },
137 { 'title' => 'me.title' },
138 { 'artist' => 'me.artist' },
140 order_by => 'me.cdid',
144 { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
145 { single_track => code(sub { null_branch ( \@_, [
151 { artistid => undef }
158 { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
159 { single_track => code(sub { null_branch ( \@_, [
165 { artistid => undef }
172 { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
186 { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
187 { single_track => code(sub { null_branch ( \@_, [
193 { artistid => undef }
200 "Simple 1:1 descend with missing selectors $native_inflator",
204 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
205 prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
206 order_by => [qw/me.cdid tracks.trackid/],
210 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
211 { single_track => code(sub { null_collapsed_branch ( \@_, [
212 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
214 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
217 { artistid => undef, name => undef, charfield => undef, rank => undef },
218 { cds => code(sub { null_collapsed_branch ( \@_, [ [
219 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
220 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
221 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
230 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
231 { single_track => code(sub { null_collapsed_branch ( \@_, [
232 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
234 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
237 { artistid => undef, name => undef, charfield => undef, rank => undef },
238 { cds => code(sub { null_collapsed_branch ( \@_, [ [
239 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
240 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
241 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
250 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
252 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
254 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
257 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
260 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
261 { tracks => code(sub { null_collapsed_branch ( \@_, [
262 [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
266 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
268 [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
269 [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
270 [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
271 [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
275 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
277 [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
278 [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
282 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
284 [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
285 [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
286 [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
296 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
297 { single_track => code(sub { null_collapsed_branch ( \@_, [
298 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
300 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
303 { artistid => undef, name => undef, charfield => undef, rank => undef },
304 { cds => code(sub { null_collapsed_branch ( \@_, [ [
305 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
306 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
307 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
316 "Collapsing 1:1 ending in chained has_many with classic prefetch $native_inflator",
320 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
321 join => { cds => 'tracks' },
323 (map { "cds.$_" } $schema->source('CD')->columns),
324 (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns),
326 order_by => [qw/cds.cdid tracks.trackid me.name/],
330 { artistid => 3, name => 'A_cdless', charfield => undef, rank => 13 },
331 { cds => code(sub { null_branch ( \@_, [
332 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
333 { tracks => code(sub { null_branch ( \@_, [
334 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
339 { artistid => 2, name => 'Z_cdless', charfield => undef, rank => 13 },
340 { cds => code(sub { null_branch ( \@_, [
341 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
342 { tracks => code(sub { null_branch ( \@_, [
343 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
348 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
350 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
352 { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef },
357 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
359 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
361 { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
366 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
368 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
370 { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
375 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
377 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
379 { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
384 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
386 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
388 { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
393 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
395 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
397 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
402 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
404 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
406 { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
411 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
413 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
415 { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
420 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
422 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
424 { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
429 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
431 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
432 { tracks => code(sub { null_branch ( \@_, [
433 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
438 "Non-Collapsing chained has_many $native_inflator",
442 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
445 columns => [qw( cds.title cds.artist )],
446 order_by => [qw( me.name cds.title )],
451 { cds => code(sub { null_collapsed_branch ( \@_, [
452 [ { artist => undef, title => undef } ]
458 [ { artist => 1, title => "Equinoxe" } ],
459 [ { artist => 1, title => "Magnetic Fields" } ],
460 [ { artist => 1, title => "Oxygene" } ],
461 [ { artist => 1, title => "fuzzy_1" } ],
466 { cds => code(sub { null_collapsed_branch ( \@_, [
467 [ { artist => undef, title => undef } ]
471 "Expected output of collapsing 1:M with empty root selection $native_inflator",
475 rs_contents( $schema->resultset ('CD')->search_rs (
477 'tracks.title' => 'e2',
478 'cds.title' => 'Oxygene',
484 { single_track => { cd => 'mandatory_artwork' } },
485 { artist => { cds => 'mandatory_artwork'} },
489 'single_track.cd.mandatory_artwork.cd_id' => 'mandatory_artwork.cd_id',
490 'artist.cds.mandatory_artwork.cd_id' => 'mandatory_artwork_2.cd_id',
501 { mandatory_artwork => [ { cd_id => 2 } ] }
509 { mandatory_artwork => [ { cd_id => 2 } ] }
521 $native_inflator ? undef : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
524 sub null_collapsed_branch {
527 $native_inflator ? [] : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
532 package DBICTest::_IRCapture;
533 sub inflate_result { [@_[2,3]] };
538 $rs->result_class('DBICTest::_IRCapture');
539 die 'eeeeek - preprocessed $rs' if defined $rs->{_result_inflator}{is_core_row};
540 $rs->{_result_inflator}{is_core_row} = 1 if $native_inflator;
545 my ($left, $right, $msg) = @_;
547 local $Test::Builder::Level = $Test::Builder::Level + 1;
548 cmp_deeply($left, $right, $msg||()) or next INFTYPE;
552 package DBICTest::_DoubleResult;
556 return map { DBIx::Class::ResultClass::HashRefInflator->inflate_result(@_) } (1,2);
560 my $oxygene_rs = $schema->resultset('CD')->search({ 'me.title' => 'Oxygene' });
563 [ $oxygene_rs->search({}, { result_class => 'DBICTest::_DoubleResult' })->all ],
564 [ ({ $oxygene_rs->single->get_columns }) x 2 ],
568 [ $oxygene_rs->search({}, {
569 result_class => 'DBICTest::_DoubleResult', prefetch => [qw(artist tracks)],
570 order_by => [qw(me.cdid tracks.title)],
572 [ (@{$oxygene_rs->search({}, {
573 prefetch=> [qw(artist tracks)],
574 order_by => [qw(me.cdid tracks.title)],