[Bast-commits] r8659 - in
DBIx-Class/0.08/branches/resultset-remove-columns:
lib/DBIx/Class t/search
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Fri Feb 12 05:19:03 GMT 2010
Author: frew
Date: 2010-02-12 05:19:02 +0000 (Fri, 12 Feb 2010)
New Revision: 8659
Modified:
DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/branches/resultset-remove-columns/t/search/select_chains.t
Log:
initial commit and a single test for remove-columns
Modified: DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm 2010-02-12 04:54:46 UTC (rev 8658)
+++ DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm 2010-02-12 05:19:02 UTC (rev 8659)
@@ -2778,10 +2778,27 @@
$attrs->{columns} ||= delete $attrs->{cols} if exists $attrs->{cols};
my @colbits;
+ my @del_colbits;
# build columns (as long as select isn't set) into a set of as/select hashes
unless ( $attrs->{select} ) {
+ my @del_cols = @{ delete $attrs->{'remove-columns'} || [] };
+
+ for (@del_cols) {
+ if ( ref $_ eq 'HASH' ) {
+ push @del_colbits, $_
+ } else {
+ my $key = /^\Q${alias}.\E(.+)$/
+ ? "$1"
+ : "$_";
+ my $value = /\./
+ ? "$_"
+ : "${alias}.$_";
+ push @del_colbits, { $key => $value };
+ }
+ }
+
my @cols;
if ( ref $attrs->{columns} eq 'ARRAY' ) {
@cols = @{ delete $attrs->{columns}}
@@ -2806,24 +2823,6 @@
}
}
- # add the additional columns on
- foreach (qw{include_columns +columns}) {
- if ( $attrs->{$_} ) {
- my @list = ( ref($attrs->{$_}) eq 'ARRAY' )
- ? @{ delete $attrs->{$_} }
- : delete $attrs->{$_};
- for (@list) {
- if ( ref($_) eq 'HASH' ) {
- push @colbits, $_
- } else {
- my $key = ( split /\./, $_ )[-1];
- my $value = ( /\./ ? $_ : "$alias.$_" );
- push @colbits, { $key => $value };
- }
- }
- }
- }
-
# start with initial select items
if ( $attrs->{select} ) {
$attrs->{select} =
@@ -2858,6 +2857,44 @@
push @{ $attrs->{select} }, map values %{$_}, @colbits;
push @{ $attrs->{as} }, map keys %{$_}, @colbits;
+ if ( @del_colbits) {
+ push @{ $attrs->{'remove-select'} }, map values( %{$_} ), @del_colbits;
+ push @{ $attrs->{'remove-as'} }, map keys( %{$_} ), @del_colbits;
+ }
+
+ if (my $dels = delete $attrs->{'remove-select'}) {
+ for my $del (@{$dels}) {
+ $attrs->{select} = [grep !ref $_ && $_ ne $del, @{$attrs->{select}}];
+ }
+ }
+
+ if (my $dels = delete $attrs->{'remove-as'}) {
+ for my $del (@{$dels}) {
+ $attrs->{as} = [grep !ref $_ && $_ ne $del, @{$attrs->{as}}];
+ }
+ }
+
+ # add the additional columns on
+ @colbits = ();
+ foreach (qw{include_columns +columns}) {
+ if ( $attrs->{$_} ) {
+ my @list = ( ref($attrs->{$_}) eq 'ARRAY' )
+ ? @{ delete $attrs->{$_} }
+ : delete $attrs->{$_};
+ for (@list) {
+ if ( ref($_) eq 'HASH' ) {
+ push @colbits, $_
+ } else {
+ my $key = ( split /\./, $_ )[-1];
+ my $value = ( /\./ ? $_ : "$alias.$_" );
+ push @colbits, { $key => $value };
+ }
+ }
+ }
+ }
+ push( @{ $attrs->{select} }, map { values( %{$_} ) } @colbits );
+ push( @{ $attrs->{as} }, map { keys( %{$_} ) } @colbits );
+
if ( my $adds = delete $attrs->{'+select'} ) {
$adds = [$adds] unless ref $adds eq 'ARRAY';
push @{ $attrs->{select} },
Modified: DBIx-Class/0.08/branches/resultset-remove-columns/t/search/select_chains.t
===================================================================
--- DBIx-Class/0.08/branches/resultset-remove-columns/t/search/select_chains.t 2010-02-12 04:54:46 UTC (rev 8658)
+++ DBIx-Class/0.08/branches/resultset-remove-columns/t/search/select_chains.t 2010-02-12 05:19:02 UTC (rev 8659)
@@ -37,6 +37,11 @@
{
columns => [ 'year' ],
} => 'SELECT me.year FROM cd me',
+
+ {
+ '+columns' => [ 'cdid' ],
+ 'remove-columns' => [qw{cdid year}],
+ } => 'SELECT me.cdid FROM cd me',
);
my $rs = $schema->resultset('CD');
More information about the Bast-commits
mailing list