X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=blobdiff_plain;f=t%2Fprefetch%2Fincomplete.t;h=36f259ff69d1b8cb885a088560e723f2951cef77;hp=c2a2b157aade49f68ac3d709f833bb771c712316;hb=fe0708a2d68b5d34b6bc6f7e70164c3e569f1dd0;hpb=4b8da207a3460216711d73987feaa13f7107ecc3 diff --git a/t/prefetch/incomplete.t b/t/prefetch/incomplete.t index c2a2b15..36f259f 100644 --- a/t/prefetch/incomplete.t +++ b/t/prefetch/incomplete.t @@ -21,7 +21,7 @@ lives_ok(sub { prefetch => [ qw/ cds / ], order_by => [ { -desc => 'me.name' }, 'cds.title' ], select => [qw/ me.name cds.title / ], - } + }, ); is ($rs->count, 2, 'Correct number of collapsed artists'); @@ -32,6 +32,57 @@ lives_ok(sub { }, 'explicit prefetch on a keyless object works'); +lives_ok ( sub { + + my $rs = $schema->resultset('CD')->search( + {}, + { + order_by => [ { -desc => 'me.year' } ], + } + ); + my $years = [qw/ 2001 2001 1999 1998 1997/]; + + is_deeply ( + [ $rs->search->get_column('me.year')->all ], + $years, + 'Expected years (at least one duplicate)', + ); + + my @cds_and_tracks; + for my $cd ($rs->all) { + my $data->{year} = $cd->year; + for my $tr ($cd->tracks->all) { + push @{$data->{tracks}}, { $tr->get_columns }; + } + push @cds_and_tracks, $data; + } + + my $pref_rs = $rs->search ({}, { columns => ['year'], prefetch => 'tracks' }); + + my @pref_cds_and_tracks; + for my $cd ($pref_rs->all) { + my $data = { $cd->get_columns }; + for my $tr ($cd->tracks->all) { + push @{$data->{tracks}}, { $tr->get_columns }; + } + push @pref_cds_and_tracks, $data; + } + + is_deeply ( + \@pref_cds_and_tracks, + \@cds_and_tracks, + 'Correct collapsing on non-unique primary object' + ); + + is_deeply ( + [ $pref_rs->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' })->all ], + \@cds_and_tracks, + 'Correct HRI collapsing on non-unique primary object' + ); + +}, 'weird collapse lives'); + + lives_ok(sub { # test implicit prefetch as well