From: Matt S Trout Date: Fri, 14 Jul 2006 03:35:54 +0000 (+0000) Subject: fixups to ORDER BY, tweaks to deepen some copies in ResultSet X-Git-Tag: v0.07002~75^2~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d09c569a37b1bd7b79bcffd4c638d6816ac6c62a;p=dbsrgits%2FDBIx-Class.git fixups to ORDER BY, tweaks to deepen some copies in ResultSet --- diff --git a/Changes b/Changes index 9b81c05..73fc93e 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - fixups to ORDER BY, tweaks to deepen some copies in ResultSet + 0.06999_07 2006-07-12 20:58:05 - fix issue with from attr copying introduced in last release diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 611df76..fd56b5f 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1464,9 +1464,10 @@ sub _resolve_from { my $join = ($attrs->{join} ? [ $attrs->{join}, $extra_join ] : $extra_join); - push(@{$from}, - $source->resolve_join($join, $attrs->{alias}, $seen) - ); + $from = [ + @$from, + ($join ? $source->resolve_join($join, $attrs->{alias}, $seen) : ()), + ]; return ($from,$seen); } @@ -1485,13 +1486,21 @@ sub _resolved_attrs { } elsif (!$attrs->{select}) { $attrs->{columns} = [ $source->columns ]; } - - $attrs->{select} ||= [ - map { m/\./ ? $_ : "${alias}.$_" } @{delete $attrs->{columns}} - ]; - $attrs->{as} ||= [ - map { m/^\Q${alias}.\E(.+)$/ ? $1 : $_ } @{$attrs->{select}} - ]; + + $attrs->{select} = + ($attrs->{select} + ? (ref $attrs->{select} eq 'ARRAY' + ? [ @{$attrs->{select}} ] + : [ $attrs->{select} ]) + : [ map { m/\./ ? $_ : "${alias}.$_" } @{delete $attrs->{columns}} ] + ); + $attrs->{as} = + ($attrs->{as} + ? (ref $attrs->{as} eq 'ARRAY' + ? [ @{$attrs->{as}} ] + : [ $attrs->{as} ]) + : [ map { m/^\Q${alias}.\E(.+)$/ ? $1 : $_ } @{$attrs->{select}} ] + ); my $adds; if ($adds = delete $attrs->{include_columns}) { @@ -1501,7 +1510,8 @@ sub _resolved_attrs { } if ($adds = delete $attrs->{'+select'}) { $adds = [$adds] unless ref $adds eq 'ARRAY'; - push(@{$attrs->{select}}, map { /\./ || ref $_ ? $_ : "${alias}.$_" } @$adds); + push(@{$attrs->{select}}, + map { /\./ || ref $_ ? $_ : "${alias}.$_" } @$adds); } if (my $adds = delete $attrs->{'+as'}) { $adds = [$adds] unless ref $adds eq 'ARRAY'; @@ -1528,9 +1538,11 @@ sub _resolved_attrs { $attrs->{group_by} ||= $attrs->{select} if delete $attrs->{distinct}; if ($attrs->{order_by}) { - $attrs->{order_by} = [ $attrs->{order_by} ] unless ref $attrs->{order_by}; + $attrs->{order_by} = (ref($attrs->{order_by}) eq 'ARRAY' + ? [ @{$attrs->{order_by}} ] + : [ $attrs->{order_by} ]); } else { - $attrs->{order_by} ||= []; + $attrs->{order_by} = []; } my $collapse = $attrs->{collapse} || {}; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index c020071..3368ac1 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -113,8 +113,16 @@ sub _order_by { if (defined $_[0]->{order_by}) { $ret .= $self->SUPER::_order_by($_[0]->{order_by}); } - } elsif(ref $_[0] eq 'SCALAR') { + } elsif (ref $_[0] eq 'SCALAR') { $ret = $self->_sqlcase(' order by ').${ $_[0] }; + } elsif (ref $_[0] eq 'ARRAY' && @{$_[0]}) { + my @order = @{+shift}; + $ret = $self->_sqlcase(' order by ') + .join(', ', map { + my $r = $self->_order_by($_, @_); + $r =~ s/^ ?ORDER BY //i; + $r; + } @order); } else { $ret = $self->SUPER::_order_by(@_); }