From: Arthur Axel 'fREW' Schmidt Date: Sat, 26 Mar 2011 01:05:55 +0000 (-0500) Subject: fix from => $rs->as_query X-Git-Tag: v0.08191~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1bffc6b80ab92b6be1731bba24f8ea69f094b573;p=dbsrgits%2FDBIx-Class.git fix from => $rs->as_query --- diff --git a/Changes b/Changes index afca692..d9eb6b5 100644 --- a/Changes +++ b/Changes @@ -39,6 +39,7 @@ Revision history for DBIx::Class condition elements - Change SQLMaker carp-monkeypatch to be compatible with versions of SQL::Abstract >= 1.73 + - Fix using \[] literals in the from resultset attribute * Misc - Rewire all warnings to a new Carp-like implementation internal diff --git a/lib/DBIx/Class/SQLMaker.pm b/lib/DBIx/Class/SQLMaker.pm index 0fcf590..871862f 100644 --- a/lib/DBIx/Class/SQLMaker.pm +++ b/lib/DBIx/Class/SQLMaker.pm @@ -357,8 +357,12 @@ sub _table { elsif ($ref eq 'HASH') { return $_[0]->_recurse_from($_[1]); } + elsif ($ref eq 'REF' && ref ${$_[1]} eq 'ARRAY') { + my ($sql, @bind) = @{ ${$_[1]} }; + push @{$_[0]->{from_bind}}, @bind; + return $sql + } } - return $_[0]->next::method ($_[1]); } diff --git a/t/resultset/as_query.t b/t/resultset/as_query.t index 0e77078..efd5e6e 100644 --- a/t/resultset/as_query.t +++ b/t/resultset/as_query.t @@ -3,8 +3,6 @@ use warnings; use Test::More; -plan ( tests => 5 ); - use lib qw(t/lib); use DBICTest; use DBIC::SqlMakerTest; @@ -68,3 +66,28 @@ my $rscol = $art_rs->get_column( 'charfield' ); my $subsel_rs = $schema->resultset("CD")->search( { cdid => { IN => $rs->get_column('cdid')->as_query } } ); is($subsel_rs->count, $rs->count, 'Subselect on PK got the same row count'); } + + +is_same_sql_bind($schema->resultset('Artist')->search({ + rank => 1, +}, { + from => $schema->resultset('Artist')->search({ 'name' => 'frew'})->as_query, +})->as_query, + '(SELECT me.artistid, me.name, me.rank, me.charfield FROM ( + SELECT me.artistid, me.name, me.rank, me.charfield FROM + artist me + WHERE ( + ( name = ? ) + ) + ) WHERE ( + ( rank = ? ) + ) + )', + [ + [{ dbic_colname => 'name', sqlt_datatype => 'varchar', sqlt_size => 100 }, 'frew'], + [{ dbic_colname => 'rank' }, 1], + ], + 'from => ...->as_query works' +); + +done_testing;