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);
}
} 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}) {
}
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';
$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} || {};
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(@_);
}