X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F76select.t;h=164f58e322bb536da3043b0cb5dc98b2062ca1fe;hb=27ffa6c0c4e12265ea84d2b0b954a3b8954e4d69;hp=08273efedee02bb6245564e9879e21978851accd;hpb=0ca2f0d15a354a396f21e4b7fdd1da885e1fa90a;p=dbsrgits%2FDBIx-Class.git diff --git a/t/76select.t b/t/76select.t index 08273ef..164f58e 100644 --- a/t/76select.t +++ b/t/76select.t @@ -64,6 +64,7 @@ my $cds = $schema->resultset ('CD')->search ({}, { order_by => 'me.cdid'}); # ma cmp_ok ($cds->count, '>', 2, 'Initially populated with more than 2 CDs'); my $table = $cds->result_source->name; +$table = $$table if ref $table eq 'SCALAR'; my $subsel = $cds->search ({}, { columns => [qw/cdid title/], from => \ "(SELECT cdid, title FROM $table LIMIT 2) me", @@ -84,11 +85,8 @@ $rs = $schema->resultset('CD')->search({}, } ); -my @query = @${$rs->as_query}; -TODO: { local $TODO = 'as_query() inconsistent'; is (scalar @query, 2, 'as_query() returned empty bindval arrayref') || push @query, [] } - is_same_sql_bind ( - @query, + $rs->as_query, '(SELECT me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)', [], 'Use of columns attribute results in proper sql' @@ -115,11 +113,8 @@ $rs = $schema->resultset('CD')->search({}, } ); -@query = @${$rs->as_query}; -TODO: { local $TODO = 'as_query() inconsistent'; is (scalar @query, 2, 'as_query() returned empty bindval arrayref') || push @query, [] } - is_same_sql_bind ( - @query, + $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)', [], 'Use of columns attribute results in proper sql' @@ -136,3 +131,53 @@ lives_ok(sub { lives_ok(sub { $rs->first->artist->get_column('name') }, 'columns 3rd rscolumn present'); + + +$rs = $schema->resultset('CD')->search({'tracks.position' => { -in => [2] } }, + { + join => 'tracks', + columns => [qw/me.cdid me.title/], + '+select' => ['tracks.position'], + '+as' => ['track_position'], + + # get a hashref of CD1 only (the first with a second track) + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + order_by => 'cdid', + rows => 1, + } +); + +is_deeply ( + $rs->single, + { + cdid => 1, + track_position => 2, + title => 'Spoonful of bees', + }, + 'limited prefetch via column works on a multi-relationship', +); + +my $sub_rs = $rs->search ({}, + { + columns => [qw/artist tracks.trackid/], # columns should not be merged but override $rs columns + '+select' => ['tracks.title'], + '+as' => ['tracks.title'], + } +); + +is_deeply( + $sub_rs->single, + { + artist => 1, + track_position => 2, + tracks => [ + { + trackid => 17, + title => 'Apiary', + }, + ], + }, + 'columns/select/as fold properly on sub-searches', +); + +