From: Peter Rabbitson Date: Fri, 19 Jun 2009 16:41:45 +0000 (+0000) Subject: Merge 'trunk' into 'mssql_top_fixes' X-Git-Tag: v0.08108~12^2~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc185c328c2881bbafb597ffba48a516f3f8bfeb;p=dbsrgits%2FDBIx-Class.git Merge 'trunk' into 'mssql_top_fixes' r6690@Thesaurus (orig r6689): timbunce | 2009-06-16 15:06:07 +0200 Removed wording from txn_do that implies the coderef could be executed more than once. r6691@Thesaurus (orig r6690): timbunce | 2009-06-16 15:14:23 +0200 Added doc note that txn_commit does not perform an actual storage commit unless there's a DBIx::Class transaction currently in effect r6692@Thesaurus (orig r6691): timbunce | 2009-06-16 15:40:11 +0200 Reverted doc patch r6689 for now, sadly. I'll open a ticket to explain. r6694@Thesaurus (orig r6693): ribasushi | 2009-06-16 17:22:59 +0200 Fix possible regression with prefetch select resolution r6699@Thesaurus (orig r6698): wintrmute | 2009-06-17 10:32:30 +0200 Replace vague language around whether load_classes/namespaces is preferred, with an explanation that load_namespaces() is generally preferred, and explain when load_classes is appropriate. r6702@Thesaurus (orig r6701): caelum | 2009-06-17 19:50:47 +0200 fix page with offset bug r6704@Thesaurus (orig r6703): ribasushi | 2009-06-18 08:40:18 +0200 Cleanup attribute handling - I deal with resolved attributes throughout, no point in complicating things further r6705@Thesaurus (orig r6704): abraxxa | 2009-06-18 12:30:01 +0200 added test for nested has_many prefetch without entries r6707@Thesaurus (orig r6706): ribasushi | 2009-06-18 12:43:36 +0200 HRI fix r6708@Thesaurus (orig r6707): ribasushi | 2009-06-18 14:05:42 +0200 wtf r6714@Thesaurus (orig r6713): caelum | 2009-06-19 01:03:01 +0200 fix broken link in manual r6726@Thesaurus (orig r6725): ribasushi | 2009-06-19 17:25:19 +0200 r6706@Thesaurus (orig r6705): ribasushi | 2009-06-18 12:30:08 +0200 Branch to attempt prefetch with limit fix r6709@Thesaurus (orig r6708): ribasushi | 2009-06-18 15:54:38 +0200 This seems to be the prefetch+limit fix - ugly as hell but appears to work r6710@Thesaurus (orig r6709): ribasushi | 2009-06-18 16:13:31 +0200 More comments r6717@Thesaurus (orig r6716): ribasushi | 2009-06-19 15:39:43 +0200 single() throws with has_many prefetch r6718@Thesaurus (orig r6717): ribasushi | 2009-06-19 15:40:38 +0200 Rename test r6719@Thesaurus (orig r6718): ribasushi | 2009-06-19 15:44:26 +0200 cleanup svn attrs r6720@Thesaurus (orig r6719): ash | 2009-06-19 16:31:11 +0200 Add extra test for prefetch+has_many r6721@Thesaurus (orig r6720): ribasushi | 2009-06-19 16:33:49 +0200 no need to slice as use_prefetch already has a limit r6722@Thesaurus (orig r6721): ribasushi | 2009-06-19 16:36:08 +0200 throw in an extra limit, sophisticate test a bit r6723@Thesaurus (orig r6722): ribasushi | 2009-06-19 16:36:54 +0200 Fix the fix r6725@Thesaurus (orig r6724): ribasushi | 2009-06-19 17:24:23 +0200 Fix dubious optimization --- bc185c328c2881bbafb597ffba48a516f3f8bfeb diff --cc lib/DBIx/Class/ResultSet.pm index cfb736b,6faf118..74940eb --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@@ -2595,27 -2605,28 +2605,30 @@@ sub _resolved_attrs # 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) - $attrs->{_virtual_order_by} = [ $self->result_source->primary_columns ]; - + my $prefix = $alias . ($source->schema->storage->_sql_maker_opts->{name_sep} || '.'); + $attrs->{_virtual_order_by} = [ + map { $prefix . $_ } ($source->primary_columns) + ]; - my $collapse = $attrs->{collapse} || {}; + $attrs->{collapse} ||= {}; if ( my $prefetch = delete $attrs->{prefetch} ) { $prefetch = $self->_merge_attr( {}, $prefetch ); - my @pre_order; - foreach my $p ( ref $prefetch eq 'ARRAY' ? @$prefetch : ($prefetch) ) { - - # bring joins back to level of current class - my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join}); - my @prefetch = - $source->_resolve_prefetch( $p, $alias, $join_map, \@pre_order, $collapse ); - push( @{ $attrs->{select} }, map { $_->[0] } @prefetch ); - push( @{ $attrs->{as} }, map { $_->[1] } @prefetch ); - } - push( @{ $attrs->{order_by} }, @pre_order ); + + my $prefetch_ordering = []; + + my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join}); + + my @prefetch = + $source->_resolve_prefetch( $prefetch, $alias, $join_map, $prefetch_ordering, $attrs->{collapse} ); + + push( @{ $attrs->{select} }, map { $_->[0] } @prefetch ); + push( @{ $attrs->{as} }, map { $_->[1] } @prefetch ); + + push( @{ $attrs->{order_by} }, @$prefetch_ordering ); + $attrs->{_collapse_order_by} = \@$prefetch_ordering; } + if (delete $attrs->{distinct}) { $attrs->{group_by} ||= [ grep { !ref($_) || (ref($_) ne 'HASH') } @{$attrs->{select}} ]; } diff --cc lib/DBIx/Class/Storage/DBI.pm index e8611cd,e0799df..db8d2f0 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@@ -1226,21 -1226,13 +1226,15 @@@ sub _select_args_to_query } sub _select_args { - my ($self, $ident, $select, $condition, $attrs) = @_; + my ($self, $ident, $select, $where, $attrs) = @_; my $sql_maker = $self->sql_maker; + $sql_maker->{_dbic_rs_attrs} = $attrs; + - my $order = { map - { $attrs->{$_} ? ( $_ => $attrs->{$_} ) : () } - (qw/order_by group_by having _virtual_order_by/ ) - }; - - - my $bind_attrs = {}; - my $alias2source = $self->_resolve_ident_sources ($ident); + # calculate bind_attrs before possible $ident mangling + my $bind_attrs = {}; for my $alias (keys %$alias2source) { my $bindtypes = $self->source_bind_attributes ($alias2source->{$alias}) || {}; for my $col (keys %$bindtypes) {