use warnings;
use Test::More;
+use Test::Deep;
use lib qw(t/lib);
use DBICTest;
my $schema = DBICTest->init_schema(no_populate => 1);
+$schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
+ title => 'Magnetic Fields',
+ year => 1981,
+ genre => { name => 'electro' },
+ tracks => [
+ { title => 'm1' },
+ { title => 'm2' },
+ { title => 'm3' },
+ { title => 'm4' },
+ ],
+} ] });
+
$schema->resultset('CD')->create({
title => 'Equinoxe',
year => 1978,
cd => {
title => 'Oxygene',
year => 1976,
- artist => {
- name => 'JMJ',
- cds => [
- {
- title => 'Magnetic Fields',
- year => 1981,
- genre => { name => 'electro' },
- tracks => [
- { title => 'm1' },
- { title => 'm2' },
- { title => 'm3' },
- { title => 'm4' },
- ],
- },
- ],
- },
+ artist => { name => 'JMJ' },
tracks => [
{ title => 'o2', position => 2}, # the position should not be needed here, bug in MC
],
},
});
+$schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1" });
+
{
package DBICTest::_IRCapture;
sub inflate_result { [@_[2,3]] };
}
-is_deeply(
+{
+ package DBICTest::_IRCaptureAround;
+ use base 'DBIx::Class::Row';
+ sub inflate_result { [@_[2,3]] };
+}
+
+cmp_structures(
([$schema->resultset ('CD')->search ({}, {
result_class => 'DBICTest::_IRCapture',
prefetch => { single_track => { cd => 'artist' } },
[
[
{ cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
- { single_track => [
+ { single_track => bless( [
{ trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
- { cd => [
+ { cd => bless ( [
{ cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
{
- artist => [
+ artist => bless ( [
{ artistid => undef, name => undef, charfield => undef, rank => undef }
- ]
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
}
- ] }
- ] }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
],
[
{ cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
- { single_track => [
+ { single_track => bless( [
{ trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
- { cd => [
+ { cd => bless ( [
{ cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
{
- artist => [
+ artist => bless ( [
{ artistid => undef, name => undef, charfield => undef, rank => undef }
- ]
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
}
- ] }
- ] }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
],
[
{ cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
] }
] }
],
+ [
+ { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+ { single_track => bless( [
+ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+ { cd => bless ( [
+ { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
+ {
+ artist => bless ( [
+ { artistid => undef, name => undef, charfield => undef, rank => undef }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
+ }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+ ],
],
- 'Simple 1:1 descend with classic prefetch ok'
+ 'Simple 1:1 descend with classic prefetch'
);
-is_deeply(
+cmp_structures(
[$schema->resultset ('CD')->search ({}, {
result_class => 'DBICTest::_IRCapture',
join => { single_track => { cd => 'artist' } },
[
[
{ artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
- { single_track => [
+ { single_track => bless( [
undef,
{ cd => [
undef,
]
}
] }
- ] }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
],
[
{ artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
- { single_track => [
+ { single_track => bless( [
undef,
{ cd => [
undef,
]
}
] }
- ] }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
],
[
{ artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
] }
] }
],
+ [
+ { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+ { single_track => bless( [
+ undef,
+ { cd => [
+ undef,
+ {
+ artist => [
+ { artistid => undef }
+ ]
+ }
+ ] }
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+ ],
],
- 'Simple 1:1 descend with missing selectors ok'
+ 'Simple 1:1 descend with missing selectors'
);
-is_deeply(
+cmp_structures(
([$schema->resultset ('CD')->search ({}, {
result_class => 'DBICTest::_IRCapture',
prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
[
[
{ cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
- { single_track => [
+ { single_track => bless( [
{ trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
{ cd => [
{ cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
{
artist => [
{ artistid => undef, name => undef, charfield => undef, rank => undef },
- { cds => [ [
+ { cds => bless( [ [
{ cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
- { tracks => [ [
+ { tracks => bless( [ [
{ trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
- ] ] },
- ]]},
+ ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
],
},
] },
- ] },
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
],
[
{ cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
- { single_track => [
+ { single_track => bless( [
{ trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
{ cd => [
{ cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
{
artist => [
{ artistid => undef, name => undef, charfield => undef, rank => undef },
- { cds => [ [
+ { cds => bless( [ [
{ cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
- { tracks => [ [
+ { tracks => bless( [ [
{ trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
- ] ] },
- ]]},
- ]
- }
- ] }
- ] }
+ ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ],
+ },
+ ] },
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
],
[
{ cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
{ artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
{ cds => [
[
+ { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+ { tracks => bless( [
+ [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ],
+ [
{ cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
{ tracks => [
[ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
] }
] }
],
+ [
+ { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+ { single_track => bless( [
+ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+ { cd => [
+ { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
+ {
+ artist => [
+ { artistid => undef, name => undef, charfield => undef, rank => undef },
+ { cds => bless( [ [
+ { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
+ { tracks => bless( [ [
+ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+ ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ],
+ },
+ ] },
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ],
],
- 'Collapsing 1:1 ending in chained has_many with classic prefetch ok'
+ 'Collapsing 1:1 ending in chained has_many with classic prefetch'
);
-is_deeply (
+cmp_structures (
([$schema->resultset ('Artist')->search ({}, {
result_class => 'DBICTest::_IRCapture',
join => { cds => 'tracks' },
]},
]},
],
+ [
+ { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
+ { cds => [
+ { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
+ { tracks => bless( [
+ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
+ ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+ ]},
+ ],
],
- 'Non-Collapsing chained has_many ok'
+ 'Non-Collapsing chained has_many'
);
+$schema->resultset('Artist')->create({ name => "${_}_cdless" })
+ for (qw( Z A ));
+
+cmp_structures (
+ [$schema->resultset ('Artist')->search ({}, {
+ result_class => 'DBICTest::_IRCapture',
+ collapse => 1,
+ join => 'cds',
+ columns => [qw( cds.title cds.artist )],
+ order_by => [qw( me.name cds.title )],
+ })->all],
+ [
+ [
+ undef,
+ { cds => bless( [
+ [ { artist => undef, title => undef } ]
+ ], 'DBIx::ResultParser::RelatedNullBranch' ) },
+ ],
+ [
+ undef,
+ { cds => [
+ [ { artist => 1, title => "Equinoxe" } ],
+ [ { artist => 1, title => "Magnetic Fields" } ],
+ [ { artist => 1, title => "Oxygene" } ],
+ [ { artist => 1, title => "fuzzy_1" } ],
+ ] }
+ ],
+ [
+ undef,
+ { cds => bless( [
+ [ { artist => undef, title => undef } ]
+ ], 'DBIx::ResultParser::RelatedNullBranch' ) },
+ ],
+ ],
+ 'Expected output of collapsing 1:M with empty root selection',
+);
+
+sub cmp_structures {
+ my ($left, $right, $msg) = @_;
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ cmp_deeply($left, $right, $msg||());
+}
+
done_testing;