From: Norbert Buchmuller Date: Mon, 17 Nov 2008 02:11:42 +0000 (+0100) Subject: Merge 'resultsetcolumn_custom_columns' into 'trunk' X-Git-Tag: v0.08240~237 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=152002c48f71b635f56c2a1709581a6f7e5e6650;p=dbsrgits%2FDBIx-Class.git Merge 'resultsetcolumn_custom_columns' into 'trunk' r5165@vger: mendel | 2008-11-16 20:11:42 +0100 * Merged in changes from 'resultsetcolumn_custom_columns' branch, --- 152002c48f71b635f56c2a1709581a6f7e5e6650 diff --cc lib/DBIx/Class/ResultSetColumn.pm index 68cc4e0,167cd02..7b0fee6 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@@ -36,8 -37,16 +37,19 @@@ sub new my ($class, $rs, $column) = @_; $class = ref $class if ref $class; my $new_parent_rs = $rs->search_rs; # we don't want to mess up the original, so clone it - $new_parent_rs->{attrs}->{prefetch} = undef; # prefetch causes additional columns to be fetched - my $new = bless { _column => $column, _parent_resultset => $new_parent_rs }, $class; + my $attrs = $new_parent_rs->_resolved_attrs; + $new_parent_rs->{attrs}->{$_} = undef for qw(prefetch include_columns +select +as); # prefetch, include_columns, +select, +as cause additional columns to be fetched + ++ # 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 $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; }