];
}
- if ( $attrs->{order_by} ) {
+ if ( defined $attrs->{order_by} ) {
$attrs->{order_by} = (
ref( $attrs->{order_by} ) eq 'ARRAY'
? [ @{ $attrs->{order_by} } ]
- : [ $attrs->{order_by} ]
+ : [ $attrs->{order_by} || () ]
);
}
$attrs->{group_by} = [ $attrs->{group_by} ];
}
- # If the order_by is otherwise empty - we will use this for TOP limit
- # emulation and the like.
- # Although this is needed only if the order_by is not defined, it is
- # actually cheaper to just populate this rather than properly examining
- # order_by (stuf like [ {} ] and the like)
- my $prefix = $alias . ($source->schema->storage->sql_maker->{name_sep} || '.');
- $attrs->{_virtual_order_by} = [
- map { $prefix . $_ } ($source->primary_columns)
- ];
-
$attrs->{collapse} ||= {};
if ( my $prefetch = delete $attrs->{prefetch} ) {
$prefetch = $self->_merge_attr( {}, $prefetch );
push @{ $attrs->{select} }, @{$attrs->{prefetch_select}};
push @{ $attrs->{as} }, (map { $_->[1] } @prefetch);
- push( @{ $attrs->{order_by} }, @$prefetch_ordering );
+ push( @{$attrs->{order_by}}, @$prefetch_ordering );
$attrs->{_collapse_order_by} = \@$prefetch_ordering;
}
$order = { %$order }; #copy
my $req_order = $order->{order_by};
- my $limit_order =
- scalar $self->_order_by_chunks ($req_order) # examine normalized version, collapses nesting
- ? $req_order
- : $order->{_virtual_order_by}
- ;
+
+ # examine normalized version, collapses nesting
+ my $limit_order;
+ if (scalar $self->_order_by_chunks ($req_order)) {
+ $limit_order = $req_order;
+ }
+ else {
+ my $rs_alias = $self->{_dbic_rs_attrs}{alias};
+ $limit_order = [ map
+ { join ('', $rs_alias, $name_sep, $_ ) }
+ ( $self->{_dbic_rs_attrs}{_source_handle}->resolve->primary_columns )
+ ];
+ }
my ( $order_by_inner, $order_by_outer ) = $self->_order_directions($limit_order);
my $order_by_requested = $self->_order_by ($req_order);
# generate the rest
- delete $order->{$_} for qw/order_by _virtual_order_by/;
+ delete $order->{order_by};
my $grpby_having = $self->_order_by ($order);
# short circuit for counts - the ordering complexity is needless
sub _select_args {
my ($self, $ident, $select, $where, $attrs) = @_;
+ my ($alias2source, $root_alias) = $self->_resolve_ident_sources ($ident);
+
my $sql_maker = $self->sql_maker;
$sql_maker->{_dbic_rs_attrs} = {
%$attrs,
select => $select,
from => $ident,
where => $where,
+ _source_handle => $alias2source->{$root_alias}->handle,
};
- my ($alias2source, $root_alias) = $self->_resolve_ident_sources ($ident);
-
# calculate bind_attrs before possible $ident mangling
my $bind_attrs = {};
for my $alias (keys %$alias2source) {
my $order = { map
{ $attrs->{$_} ? ( $_ => $attrs->{$_} ) : () }
- (qw/order_by group_by having _virtual_order_by/ )
+ (qw/order_by group_by having/ )
};
return ('select', $attrs->{bind}, $ident, $bind_attrs, $select, $where, $order, @limit);