X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F76select.t;h=dca56546021946311aa7a5361421aa562c469797;hb=a8de639b29afc6645820ba346b47d53117dbbe7e;hp=01d62f592a7d62fce328b68286ae067e46351854;hpb=bbd828a6a6ae6408fe8cca57d8052447345aa6a9;p=dbsrgits%2FDBIx-Class.git diff --git a/t/76select.t b/t/76select.t index 01d62f5..dca5654 100644 --- a/t/76select.t +++ b/t/76select.t @@ -103,7 +103,7 @@ $rs = $schema->resultset('CD')->search({}, is_same_sql_bind ( $rs->as_query, - '(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)', + '(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)', [], 'Use of columns attribute results in proper sql' ); @@ -153,35 +153,80 @@ my $sub_rs = $rs->search ({}, } ); -is_deeply ( +is_deeply( $sub_rs->single, { - artist => 1, - track_position => 2, - tracks => - { - title => 'Apiary', - }, + artist => 1, + tracks => { + title => 'Apiary', + trackid => 17, + }, }, 'columns/select/as fold properly on sub-searches', ); -TODO: { - local $TODO = "Multi-collapsing still doesn't work right - HRI should be getting an arrayref, not an individual hash"; +# *very* esoteric use-case, yet valid (the "empty" object should not be undef): +$rs = $schema->resultset('Artist'); +$rs->create({ artistid => 69, name => 'Ranetki' }); + +my $relations_or_1_count = + $rs->search_related('cds')->count + + + $rs->search({ 'cds.cdid' => undef }, { join => 'cds' })->count +; + +my $weird_rs = $rs->search({}, { + order_by => { -desc => [ 'me.artistid', 'cds.cdid' ] }, + columns => [{ cd_title => 'cds.title', cd_year => 'cds.year' }], + join => 'cds', +}); + +my $weird_rs_hri = $weird_rs->search({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); + +for my $rs ($weird_rs, $weird_rs_hri) { + is ($rs->count, $relations_or_1_count, 'count on rhs data injection matches'); + + my @all; + while (my $r = $rs->next) { + push @all, $r; + } + + is (scalar @all, $relations_or_1_count, 'object count on rhs data injection matches'); is_deeply ( - $sub_rs->single, - { - artist => 1, - track_position => 2, - tracks => [ - { - trackid => 17, - title => 'Apiary', - }, - ], - }, - 'columns/select/as fold properly on sub-searches', + ( $rs->result_class eq 'DBIx::Class::ResultClass::HashRefInflator' + ? \@all + : [ map { +{$_->get_columns} } @all ] + ), + [ + { + cd_title => undef, + cd_year => undef, + }, + { + cd_title => "Come Be Depressed With Us", + cd_year => 1998, + }, + { + cd_title => "Generic Manufactured Singles", + cd_year => 2001, + }, + { + cd_title => "Caterwaulin' Blues", + cd_year => 1997, + }, + { + cd_title => "Forkful of bees", + cd_year => 2001, + }, + { + cd_title => "Spoonful of bees", + cd_year => 1999, + }, + ], + 'Correct data retrieved' ); + + is_deeply( [ $rs->all ], \@all, '->all matches' ); } done_testing;