X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSetColumn.pm;h=037b7714b15dd4c9d6cea3dca0179451708e310f;hb=e8b32a6d045b4d04ba023d48be1c8e32065fcec6;hp=646e0841c1f793c8b92dcc9ce33ca5c95a2b7568;hpb=0f6fc7050c1f6120a1bae77ec57def4e965ac332;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index 646e084..037b771 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -36,21 +36,31 @@ passed as params. Used internally by L. sub new { my ($class, $rs, $column) = @_; $class = ref $class if ref $class; + + $rs->throw_exception("column must be supplied") unless $column; + my $new_parent_rs = $rs->search_rs; # we don't want to mess up the original, so clone it - my $attrs = $new_parent_rs->_resolved_attrs; - $new_parent_rs->{attrs}->{prefetch} = undef; # prefetch cause additional columns to be fetched + + # prefetch causes additional columns to be fetched, but we can not just make a new + # rs via the _resolved_attrs trick - we need to retain the separation between + # +select/+as and select/as. At the same time we want to preserve any joins that the + # prefetch would otherwise generate. + my $init_attrs = $new_parent_rs->{attrs} ||= {}; + delete $init_attrs->{collapse}; + $init_attrs->{join} = $rs->_merge_attr( delete $init_attrs->{join}, delete $init_attrs->{prefetch} ); # If $column can be found in the 'as' list of the parent resultset, use the # corresponding element of its 'select' list (to keep any custom column # definition set up with 'select' or '+select' attrs), otherwise use $column # (to create a new column definition on-the-fly). + my $attrs = $new_parent_rs->_resolved_attrs; + my $as_list = $attrs->{as} || []; my $select_list = $attrs->{select} || []; my $as_index = List::Util::first { ($as_list->[$_] || "") eq $column } 0..$#$as_list; my $select = defined $as_index ? $select_list->[$as_index] : $column; my $new = bless { _select => $select, _as => $column, _parent_resultset => $new_parent_rs }, $class; - $new->throw_exception("column must be supplied") unless $column; return $new; } @@ -58,7 +68,7 @@ sub new { =over 4 -=item Arguments: See L +=item Arguments: none =item Return Value: \[ $sql, @bind ]