From: Peter Rabbitson Date: Thu, 2 Jul 2009 23:21:28 +0000 (+0000) Subject: Some hack consolidation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e2db8319f8e463bc3136e4aec9372a1e8305ac26;p=dbsrgits%2FDBIx-Class-Historic.git Some hack consolidation --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 32f6b5a..fae8f01 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2861,11 +2861,11 @@ sub _resolved_attrs { ]; } - 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} || () ] ); } @@ -2873,16 +2873,6 @@ sub _resolved_attrs { $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 ); @@ -2898,7 +2888,7 @@ sub _resolved_attrs { 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; } diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index 2698ab7..e6ae5b5 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -212,17 +212,25 @@ sub _Top { $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 diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index f1a977e..ba36ad6 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1376,16 +1376,17 @@ sub _select_args_to_query { 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) { @@ -1445,7 +1446,7 @@ sub _select_args { 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);