1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
13 my $schema = DBICTest->init_schema(no_populate => 1);
15 $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
16 title => 'Magnetic Fields',
18 genre => { name => 'electro' },
27 $schema->resultset('CD')->create({
30 artist => { name => 'JMJ' },
31 genre => { name => 'electro' },
42 artist => { name => 'JMJ' },
45 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
51 $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" });
53 $schema->resultset('Artist')->create({ name => "${_}_cdless" })
56 # subs at the end of the test refer to this
60 # run entire test twice - with and without "native inflator"
61 INFTYPE: for ('', '(native inflator)') {
63 $native_inflator = $_;
66 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
67 prefetch => { single_track => { cd => 'artist' } },
68 order_by => 'me.cdid',
72 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
73 { single_track => code(sub { null_branch ( \@_, [
74 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
75 { cd => code(sub { null_branch ( \@_, [
76 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
78 artist => code(sub { null_branch ( \@_, [
79 { artistid => undef, name => undef, charfield => undef, rank => undef }
86 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
87 { single_track => code(sub { null_branch ( \@_, [
88 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
89 { cd => code(sub { null_branch ( \@_, [
90 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
92 artist => code(sub { null_branch ( \@_, [
93 { artistid => undef, name => undef, charfield => undef, rank => undef }
100 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
102 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
104 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
107 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
114 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
115 { single_track => code(sub { null_branch ( \@_, [
116 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
117 { cd => code(sub { null_branch ( \@_, [
118 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
120 artist => code(sub { null_branch ( \@_, [
121 { artistid => undef, name => undef, charfield => undef, rank => undef }
128 "Simple 1:1 descend with classic prefetch $native_inflator"
132 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
133 join => { single_track => { cd => 'artist' } },
135 { 'year' => 'me.year' },
136 { 'genreid' => 'me.genreid' },
137 { 'single_track.cd.artist.artistid' => 'artist.artistid' },
138 { 'title' => 'me.title' },
139 { 'artist' => 'me.artist' },
141 order_by => 'me.cdid',
145 { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
146 { single_track => code(sub { null_branch ( \@_, [
152 { artistid => undef }
159 { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
160 { single_track => code(sub { null_branch ( \@_, [
166 { artistid => undef }
173 { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
187 { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
188 { single_track => code(sub { null_branch ( \@_, [
194 { artistid => undef }
201 "Simple 1:1 descend with missing selectors $native_inflator",
205 rs_contents( $schema->resultset ('CD')->search_rs ({}, {
206 prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
207 order_by => [qw/me.cdid tracks.trackid/],
211 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
212 { single_track => code(sub { null_collapsed_branch ( \@_, [
213 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
215 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
218 { artistid => undef, name => undef, charfield => undef, rank => undef },
219 { cds => code(sub { null_collapsed_branch ( \@_, [ [
220 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
221 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
222 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
231 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
232 { single_track => code(sub { null_collapsed_branch ( \@_, [
233 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
235 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
238 { artistid => undef, name => undef, charfield => undef, rank => undef },
239 { cds => code(sub { null_collapsed_branch ( \@_, [ [
240 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
241 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
242 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
251 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
253 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
255 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
258 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
261 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
262 { tracks => code(sub { null_collapsed_branch ( \@_, [
263 [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
267 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
269 [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
270 [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
271 [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
272 [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
276 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
278 [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
279 [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
283 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
285 [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
286 [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
287 [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
297 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
298 { single_track => code(sub { null_collapsed_branch ( \@_, [
299 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
301 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
304 { artistid => undef, name => undef, charfield => undef, rank => undef },
305 { cds => code(sub { null_collapsed_branch ( \@_, [ [
306 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
307 { tracks => code(sub { null_collapsed_branch ( \@_, [ [
308 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
317 "Collapsing 1:1 ending in chained has_many with classic prefetch $native_inflator",
321 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
322 join => { cds => 'tracks' },
324 (map { "cds.$_" } $schema->source('CD')->columns),
325 (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns),
327 order_by => [qw/cds.cdid tracks.trackid me.name/],
331 { artistid => 3, name => 'A_cdless', charfield => undef, rank => 13 },
332 { cds => code(sub { null_branch ( \@_, [
333 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
334 { tracks => code(sub { null_branch ( \@_, [
335 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
340 { artistid => 2, name => 'Z_cdless', charfield => undef, rank => 13 },
341 { cds => code(sub { null_branch ( \@_, [
342 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
343 { tracks => code(sub { null_branch ( \@_, [
344 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
349 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
351 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
353 { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef },
358 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
360 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
362 { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
367 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
369 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
371 { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
376 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
378 { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
380 { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
385 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
387 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
389 { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
394 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
396 { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
398 { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
403 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
405 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
407 { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
412 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
414 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
416 { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
421 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
423 { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
425 { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
430 { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
432 { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
433 { tracks => code(sub { null_branch ( \@_, [
434 { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
439 "Non-Collapsing chained has_many $native_inflator",
443 rs_contents( $schema->resultset ('Artist')->search_rs ({}, {
446 columns => [qw( cds.title cds.artist )],
447 order_by => [qw( me.name cds.title )],
452 { cds => code(sub { null_collapsed_branch ( \@_, [
453 [ { artist => undef, title => undef } ]
459 [ { artist => 1, title => "Equinoxe" } ],
460 [ { artist => 1, title => "Magnetic Fields" } ],
461 [ { artist => 1, title => "Oxygene" } ],
462 [ { artist => 1, title => "fuzzy_1" } ],
467 { cds => code(sub { null_collapsed_branch ( \@_, [
468 [ { artist => undef, title => undef } ]
472 "Expected output of collapsing 1:M with empty root selection $native_inflator",
476 rs_contents( $schema->resultset ('CD')->search_rs (
478 'tracks.title' => 'e2',
479 'cds.title' => 'Oxygene',
485 { single_track => { cd => 'mandatory_artwork' } },
486 { artist => { cds => 'mandatory_artwork'} },
490 'single_track.cd.mandatory_artwork.cd_id' => 'mandatory_artwork.cd_id',
491 'artist.cds.mandatory_artwork.cd_id' => 'mandatory_artwork_2.cd_id',
502 { mandatory_artwork => [ { cd_id => 2 } ] }
510 { mandatory_artwork => [ { cd_id => 2 } ] }
522 $native_inflator ? undef : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
525 sub null_collapsed_branch {
528 $native_inflator ? [] : bless( $_[1], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ),
533 package DBICTest::_IRCapture;
534 sub inflate_result { [@_[2,3]] };
539 $rs->result_class('DBICTest::_IRCapture');
540 die 'eeeeek - preprocessed $rs' if defined $rs->{_result_inflator}{is_core_row};
541 $rs->{_result_inflator}{is_core_row} = 1 if $native_inflator;
546 my ($left, $right, $msg) = @_;
548 local $Test::Builder::Level = $Test::Builder::Level + 1;
549 cmp_deeply($left, $right, $msg||()) or next INFTYPE;
554 package DBICTest::_DoubleResult;
558 return map { DBIx::Class::ResultClass::HashRefInflator->inflate_result(@_) } (1,2);
562 my $oxygene_rs = $schema->resultset('CD')->search({ 'me.title' => 'Oxygene' });
565 [ $oxygene_rs->search({}, { result_class => 'DBICTest::_DoubleResult' })->all ],
566 [ ({ $oxygene_rs->single->get_columns }) x 2 ],
570 [ $oxygene_rs->search({}, {
571 result_class => 'DBICTest::_DoubleResult', prefetch => [qw(artist tracks)],
572 order_by => [qw(me.cdid tracks.title)],
574 [ (@{$oxygene_rs->search({}, {
575 prefetch=> [qw(artist tracks)],
576 order_by => [qw(me.cdid tracks.title)],
582 package DBICTest::_DieTrying;
585 die "nyah nyah nyah";
590 $schema->resultset('CD')->search({}, { result_class => 'DBICTest::_DieTrying' })->all
591 } qr/nyah nyah nyah/, 'Exception in custom inflate_result propagated correctly';