[Bast-commits] r8609 - in
DBIx-Class/0.08/branches/resultset-remove-columns: lib/DBIx/Class t
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Thu Feb 11 05:23:09 GMT 2010
Author: frew
Date: 2010-02-11 05:23:09 +0000 (Thu, 11 Feb 2010)
New Revision: 8609
Modified:
DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/branches/resultset-remove-columns/t/76select.t
Log:
initial commit 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-11 04:41:28 UTC (rev 8608)
+++ DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm 2010-02-11 05:23:09 UTC (rev 8609)
@@ -2773,10 +2773,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'} || [] };
+
+ @del_colbits = map +{
+ (
+ /^\Q${alias}.\E(.+)$/
+ ? "$1"
+ : "$_"
+ )
+ =>
+ (
+ /\./
+ ? "$_"
+ : "${alias}.$_"
+ )
+ }, @del_cols;
+
my @cols = ( ref($attrs->{columns}) eq 'ARRAY' )
? @{ delete $attrs->{columns}}
: (
@@ -2840,7 +2857,24 @@
# now add colbits to select/as
push( @{ $attrs->{select} }, map { values( %{$_} ) } @colbits );
push( @{ $attrs->{as} }, map { keys( %{$_} ) } @colbits );
+ use Devel::Dwarn;
+ 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}}];
+ }
+ }
+
my $adds;
if ( $adds = delete $attrs->{'+select'} ) {
$adds = [$adds] unless ref $adds eq 'ARRAY';
Modified: DBIx-Class/0.08/branches/resultset-remove-columns/t/76select.t
===================================================================
--- DBIx-Class/0.08/branches/resultset-remove-columns/t/76select.t 2010-02-11 04:41:28 UTC (rev 8608)
+++ DBIx-Class/0.08/branches/resultset-remove-columns/t/76select.t 2010-02-11 05:23:09 UTC (rev 8609)
@@ -65,7 +65,33 @@
is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"');
+$rs = $schema->resultset('CD')->search({},
+ {
+ 'join' => 'artist',
+ 'columns' => ['cdid', 'title', 'artist.name'],
+ 'remove-columns' => ['title'],
+ }
+);
+is_same_sql_bind (
+ $rs->as_query,
+ '(SELECT me.cdid, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)',
+ [],
+ 'Use of remove-columns attribute results in proper sql'
+);
+
+lives_ok(sub {
+ $rs->first->get_column('cdid')
+}, 'columns 1st rscolumn present');
+
+dies_ok(sub {
+ $rs->first->get_column('title')
+}, 'remove-columns rscolumn not present');
+
+lives_ok(sub {
+ $rs->first->artist->get_column('name')
+}, 'columns 3rd rscolumn present');
+
$rs = $schema->resultset('CD')->search({},
{
'join' => 'artist',
More information about the Bast-commits
mailing list