From: Peter Rabbitson Date: Fri, 19 Apr 2013 08:21:14 +0000 (+0200) Subject: Store the final calculated select args in the original $rs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=975b573a;p=dbsrgits%2FDBIx-Class-Historic.git Store the final calculated select args in the original $rs This is extremely ugly and ineffective, but we need it for some sanity checks so that 0.08250 can ship. The whole thing needs to be reworked with a new rsattrs instance, but that's another battle --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 9cee149..af1cbe6 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -246,7 +246,7 @@ sub new { if $source->isa('DBIx::Class::ResultSourceHandle'); $attrs = { %{$attrs||{}} }; - delete @{$attrs}{qw(_related_results_construction)}; + delete @{$attrs}{qw(_sqlmaker_select_args _related_results_construction)}; if ($attrs->{page}) { $attrs->{rows} ||= 10; @@ -1004,7 +1004,7 @@ sub cursor { my $self = shift; return $self->{cursor} ||= do { - my $attrs = { %{$self->_resolved_attrs } }; + my $attrs = $self->_resolved_attrs; $self->result_source->storage->select( $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs ); @@ -1082,6 +1082,7 @@ sub single { $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs )]; + $self->{_attrs}{_sqlmaker_select_args} = $attrs->{_sqlmaker_select_args}; return undef unless @$data; $self->{_stashed_rows} = [ $data ]; $self->_construct_results->[0]; @@ -1365,7 +1366,6 @@ sub _construct_results { my $infmap = $attrs->{as}; - $self->{_result_inflator}{is_core_row} = ( ( $inflator_cref == @@ -2588,9 +2588,13 @@ sub as_query { my $attrs = { %{ $self->_resolved_attrs } }; - $self->result_source->storage->_select_args_to_query ( + my $aq = $self->result_source->storage->_select_args_to_query ( $attrs->{from}, $attrs->{select}, $attrs->{where}, $attrs ); + + $self->{_attrs}{_sqlmaker_select_args} = $attrs->{_sqlmaker_select_args}; + + $aq; } =head2 find_or_new diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index a04194d..71880a5 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -2293,21 +2293,25 @@ sub _select_args_to_query { } sub _select_args { - my ($self, $ident, $select, $where, $attrs) = @_; + my ($self, $ident, $select, $where, $orig_attrs) = @_; + + return ( + 'select', @{$orig_attrs->{_sqlmaker_select_args}} + ) if $orig_attrs->{_sqlmaker_select_args}; my $sql_maker = $self->sql_maker; my $alias2source = $self->_resolve_ident_sources ($ident); - $attrs = { - %$attrs, + my $attrs = { + %$orig_attrs, select => $select, from => $ident, where => $where, # limit dialects use this stuff # yes, some CDBICompat crap does not supply an {alias} >.< - ( $attrs->{alias} and $alias2source->{$attrs->{alias}} ) - ? ( _rsroot_rsrc => $alias2source->{$attrs->{alias}} ) + ( $orig_attrs->{alias} and $alias2source->{$orig_attrs->{alias}} ) + ? ( _rsroot_rsrc => $alias2source->{$orig_attrs->{alias}} ) : () , }; @@ -2387,7 +2391,7 @@ sub _select_args { and @$ident != 1 ) { - ($ident) = $self->_prune_unused_joins ($ident, $select, $where, $attrs); + ($ident, $attrs->{_aliastypes}) = $self->_prune_unused_joins ($ident, $select, $where, $attrs); } ### @@ -2400,7 +2404,9 @@ sub _select_args { # invoked, and that's just bad... ### - return ('select', $ident, $select, $where, $attrs, @limit_args); + return ( 'select', @{ $orig_attrs->{_sqlmaker_select_args} = [ + $ident, $select, $where, $attrs, @limit_args + ]} ); } # Returns a counting SELECT for a simple count diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index be8965f..d4f4058 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -353,7 +353,7 @@ sub _adjust_select_args_for_complex_prefetch { # scan the *remaining* from spec against different attributes, and see which joins are needed # in what role - my $outer_aliastypes = + my $outer_aliastypes = $outer_attrs->{_aliastypes} = $self->_resolve_aliastypes_from_select_args( $from, $outer_select, $where, $outer_attrs ); # unroll parents