X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F76select.t;h=b3b491ad80d324b968d2f94cbc57153c579206f2;hb=d8cf3aa31fb3d6ff7813f021fcc002663725fc41;hp=8f45fd056d2984a0c04e0137750fb2e27cf30367;hpb=18850595a07c4ca8528a896be798cfff512723e5;p=dbsrgits%2FDBIx-Class.git diff --git a/t/76select.t b/t/76select.t index 8f45fd0..b3b491a 100644 --- a/t/76select.t +++ b/t/76select.t @@ -1,11 +1,12 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; use warnings; use Test::More; use Test::Exception; -use lib qw(t/lib); -use DBICTest; -use DBIC::SqlMakerTest; + +use DBICTest ':DiffSQL'; my $schema = DBICTest->init_schema(); @@ -61,6 +62,7 @@ my $subsel = $cds->search ({}, { is ($subsel->count, 2, 'Subselect correctly limited the rs to 2 cds'); is ($subsel->next->title, $cds->next->title, 'First CD title match'); is ($subsel->next->title, $cds->next->title, 'Second CD title match'); +$cds->reset; is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"'); @@ -103,7 +105,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' ); @@ -165,4 +167,68 @@ is_deeply( 'columns/select/as fold properly on sub-searches', ); +# *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 ( + ( $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;