From: Michael Reddick Date: Fri, 20 Feb 2009 04:42:15 +0000 (+0000) Subject: fixed from => subquery test. added from => nested subquery test X-Git-Tag: v0.08240~63^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d20198ab6f52efa52942a755559908f1bee4cdc7;p=dbsrgits%2FDBIx-Class.git fixed from => subquery test. added from => nested subquery test --- diff --git a/t/search/subquery.t b/t/search/subquery.t index 1a6861a..e0f7291 100644 --- a/t/search/subquery.t +++ b/t/search/subquery.t @@ -10,7 +10,7 @@ use lib qw(t/lib); use DBICTest; use DBIC::SqlMakerTest; -plan tests => 5; +plan tests => 6; my $schema = DBICTest->init_schema(); my $art_rs = $schema->resultset('Artist'); @@ -53,8 +53,8 @@ TODO: { ); } -TODO: { - local $TODO = "'from' doesn't work with as_query yet."; +# simple from +{ my $rs = $cdrs->search( {}, { @@ -69,14 +69,13 @@ TODO: { my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.artistid, me.name, me.rank, me.charfield FROM cds me WHERE id > 20) cd2", + "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE id > 20) cd2", [], ); } # nested from -TODO: { - local $TODO = "'from' doesn't work with as_query yet."; +{ my $art_rs2 = $schema->resultset('Artist')->search({}, { from => [ { 'me' => 'artist' }, @@ -94,6 +93,41 @@ TODO: { } +# nested subquery in from +{ + my $rs = $cdrs->search( + {}, + { + alias => 'cd2', + from => [ + { cd2 => $cdrs->search( + { id => { '>' => 20 } }, + { + alias => 'cd3', + from => [ + { cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query } + ], + }, )->as_query }, + ], + }, + ); + + my $arr = $rs->as_query; + my ($query, @bind) = @{$$arr}; + is_same_sql_bind( + $query, \@bind, + "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track + FROM + (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track + FROM + (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track + FROM cd me WHERE id < 40) cd3 + WHERE id > 20) cd2", + [], + ); + +} + { my $rs = $cdrs->search({ year => {