X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=468816bcdd985ccd770984eee5579963dff9da8e;hb=5978a0e8eea03cedc3ad471b84d8eac4769f47eb;hp=97fe8ad259db24ff7cc2da1995b90cb55494be82;hpb=532c6b4e0c34797ca2afb9bf8cba94bb84ea6bd1;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 97fe8ad..468816b 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2619,27 +2619,45 @@ sub current_source_alias { # The increments happen twice per join. An even number means a # relationship specified via a search_related, whereas an odd # number indicates a join/prefetch added via attributes +# +# Also this code will wrap the current resultset (the one we +# chain to) in a subselect IFF it contains limiting attributes sub _chain_relationship { my ($self, $rel) = @_; my $source = $self->result_source; my $attrs = { %{$self->{attrs}||{}} }; - my $from = [ @{ - $attrs->{from} - || - [{ - -source_handle => $source->handle, - -alias => $attrs->{alias}, - $attrs->{alias} => $source->from, - }] - }]; + my $from; + my @force_subq_attrs = qw/offset rows/; + + if ( + ($attrs->{from} && ref $attrs->{from} ne 'ARRAY') + || + $self->_has_resolved_attr (@force_subq_attrs) + ) { + $from = [{ + -source_handle => $source->handle, + -alias => $attrs->{alias}, + $attrs->{alias} => $self->as_query, + }]; + delete @{$attrs}{@force_subq_attrs}; + } + elsif ($attrs->{from}) { #shallow copy suffices + $from = [ @{$attrs->{from}} ]; + } + else { + $from = [{ + -source_handle => $source->handle, + -alias => $attrs->{alias}, + $attrs->{alias} => $source->from, + }]; + } my $seen = { %{$attrs->{seen_join} || {} } }; my $jpath = ($attrs->{seen_join} && keys %{$attrs->{seen_join}}) ? $from->[-1][0]{-join_path} : []; - # we need to take the prefetch the attrs into account before we # ->_resolve_join as otherwise they get lost - captainL my $merged = $self->_merge_attr( $attrs->{join}, $attrs->{prefetch} );