[Bast-commits] r8610 - 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 06:01:27 GMT 2010
Author: frew
Date: 2010-02-11 06:01:27 +0000 (Thu, 11 Feb 2010)
New Revision: 8610
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:
fix such that +columns wins against 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 05:23:09 UTC (rev 8609)
+++ DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm 2010-02-11 06:01:27 UTC (rev 8610)
@@ -2822,15 +2822,6 @@
} @cols;
}
- # add the additional columns on
- foreach ( 'include_columns', '+columns' ) {
- push @colbits, map {
- ( ref($_) eq 'HASH' )
- ? $_
- : { ( split( /\./, $_ ) )[-1] => ( /\./ ? $_ : "${alias}.$_" ) }
- } ( ref($attrs->{$_}) eq 'ARRAY' ) ? @{ delete $attrs->{$_} } : delete $attrs->{$_} if ( $attrs->{$_} );
- }
-
# start with initial select items
if ( $attrs->{select} ) {
$attrs->{select} =
@@ -2857,7 +2848,7 @@
# 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;
@@ -2875,6 +2866,19 @@
}
}
+ # add the additional columns on
+ @colbits = ();
+ foreach (qw{ include_columns +columns}) {
+ push @colbits, map {
+ ( ref($_) eq 'HASH' )
+ ? $_
+ : { ( split( /\./, $_ ) )[-1] => ( /\./ ? $_ : "${alias}.$_" ) }
+ } ( ref($attrs->{$_}) eq 'ARRAY' ) ? @{ delete $attrs->{$_} } : delete $attrs->{$_} if ( $attrs->{$_} );
+ }
+ push( @{ $attrs->{select} }, map { values( %{$_} ) } @colbits );
+ push( @{ $attrs->{as} }, map { keys( %{$_} ) } @colbits );
+
+
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 05:23:09 UTC (rev 8609)
+++ DBIx-Class/0.08/branches/resultset-remove-columns/t/76select.t 2010-02-11 06:01:27 UTC (rev 8610)
@@ -64,34 +64,35 @@
is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"');
+REMOVECOLS: {
+ my $rs = $schema->resultset('CD')->search({},
+ {
+ 'join' => 'artist',
+ 'columns' => ['cdid', 'title', 'artist.name'],
+ 'remove-columns' => ['title'],
+ }
+ );
-$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'
+ );
-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');
-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');
-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');
+}
-lives_ok(sub {
- $rs->first->artist->get_column('name')
-}, 'columns 3rd rscolumn present');
-
$rs = $schema->resultset('CD')->search({},
{
'join' => 'artist',
@@ -119,7 +120,36 @@
}, 'columns 3rd rscolumn present');
+REMOVECOLSADDCOLS: {
+ my $rs = $schema->resultset('CD')->search({},
+ {
+ 'join' => 'artist',
+ '+columns' => ['title'],
+ 'columns' => ['cdid', 'title', 'artist.name'],
+ 'remove-columns' => ['title','cdid'],
+ }
+ );
+ is_same_sql_bind (
+ $rs->as_query,
+ '(SELECT artist.name, me.title FROM cd me JOIN artist artist ON artist.artistid = me.artist)',
+ [],
+ 'Use of remove-columns and +columns attribute results in proper sql'
+ );
+
+ dies_ok(sub {
+ $rs->first->get_column('cdid')
+ }, 'remove-columns 2nd rscolumn not present');
+
+ lives_ok(sub {
+ $rs->first->get_column('title')
+ }, '+columns 1st rscolumn 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