From: Peter Rabbitson Date: Wed, 5 May 2010 11:01:35 +0000 (+0000) Subject: Changes X-Git-Tag: v0.08122~85 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec78160496ad2dbacb21b0f39350d5b42162a827;p=dbsrgits%2FDBIx-Class.git Changes --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 3805812..7ac07ca 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1289,11 +1289,6 @@ sub _count_subq_rs { $sub_attrs->{select} = @pcols ? \@pcols : [ 1 ]; } - - # this is so that the query can be simplified e.g. - # * ordering can be thrown away in things like Top limit - $sub_attrs->{-for_count_only} = 1; - return $rsrc->resultset_class ->new ($rsrc, $sub_attrs) ->as_subselect_rs @@ -2684,15 +2679,22 @@ sub as_subselect_rs { my $attrs = $self->_resolved_attrs; - return $self->result_source->resultset->search( undef, { + my $fresh_rs = (ref $self)->new ( + $self->result_source + ); + + # these pieces will be locked in the subquery + delete $fresh_rs->{cond}; + delete @{$fresh_rs->{attrs}}{qw/where bind/}; + + return $fresh_rs->search( {}, { from => [{ $attrs->{alias} => $self->as_query, -alias => $attrs->{alias}, -source_handle => $self->result_source->handle, }], - map { $_ => $attrs->{$_} } qw/select as alias/ - - }); + alias => $attrs->{alias}, + }); } # This code is called by search_related, and makes sure there diff --git a/t/resultset/as_subselect_rs.t b/t/resultset/as_subselect_rs.t index c143d11..1453f63 100644 --- a/t/resultset/as_subselect_rs.t +++ b/t/resultset/as_subselect_rs.t @@ -22,4 +22,21 @@ lives_ok { $new_rs->search({ 'artwork_to_artist.artwork_cd_id' => 1})->as_subsel '... and chaining off the virtual view works'; dies_ok { $new_rs->as_subselect_rs->search({'artwork_to_artist.artwork_cd_id'=> 1})->count } q{... but chaining off of a virtual view using join doesn't work}; + +my $book_rs = $schema->resultset ('BooksInLibrary')->search ({}, { join => 'owner' }); + +is_same_sql_bind ( + $book_rs->as_subselect_rs->as_query, + '(SELECT me.id, me.source, me.owner, me.title, me.price + FROM ( + SELECT me.id, me.source, me.owner, me.title, me.price + FROM books me + JOIN owners owner ON owner.id = me.owner + WHERE ( source = ? ) + ) me + )', + [ [ source => 'Library' ] ], + 'Resultset-class attributes do not seep outside of the subselect', +); + done_testing;