From: Nigel Metheringham Date: Wed, 12 Nov 2008 19:04:11 +0000 (+0000) Subject: Passes all tests X-Git-Tag: v0.08240~56^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=67ba664605de95b5130b55397c7351f53dae4c19;p=dbsrgits%2FDBIx-Class.git Passes all tests --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 99c99cb..59d7d06 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2080,37 +2080,25 @@ sub _resolved_attrs { $attrs->{columns} ||= delete $attrs->{cols} if exists $attrs->{cols}; my @colbits; - # build columns (as long as select isn't set), include_columns and +columns - # into a set of as/select hashes - foreach my $col ( - ( - $attrs->{select} ? () - : @{ delete $attrs->{columns} || [ $source->columns ] } - ), - ( - $attrs->{include_columns} ? @{ delete $attrs->{include_columns} } - : () - ), - ( $attrs->{'+columns'} ? @{ delete $attrs->{'+columns'} } : () ) - ) - { - if ( ref($col) eq 'HASH' ) { - push( @colbits, $col ); - } - else { - push( - @colbits, - { - ( - ( $col =~ m/^\Q${alias}.\E(.+)$/ ) ? $1 - : $col - ) => ( - ( $col =~ m/\./ ) ? $col - : "${alias}.${col}" - ) - } - ); - } + # build columns (as long as select isn't set) into a set of as/select hashes + unless ( $attrs->{select} ) { + @colbits = map { + ( ref($_) eq 'HASH' ) ? $_ + : { + ( + /^\Q${alias}.\E(.+)$/ ? $1 + : $_ + ) => ( /\./ ? $_ : "${alias}.$_" ) + } + } @{ delete $attrs->{columns} || [ $source->columns ] }; + } + # add the additional columns on + foreach ( 'include_columns', '+columns' ) { + push @colbits, map { + ( ref($_) eq 'HASH' ) + ? $_ + : { ( split( /\./, $_ ) )[-1] => ( /\./ ? $_ : "${alias}.$_" ) } + } @{ delete $attrs->{$_} } if ( $attrs->{$_} ); } # start with initial select items @@ -2131,7 +2119,7 @@ sub _resolved_attrs { } else { - # otherwise we intialise select & as + # otherwise we intialise select & as to empty $attrs->{select} = []; $attrs->{as} = []; } diff --git a/t/60core.t b/t/60core.t index 808b6b4..ea330ae 100644 --- a/t/60core.t +++ b/t/60core.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 84; +plan tests => 88; eval { require DateTime::Format::MySQL }; my $NO_DTFM = $@ ? 1 : 0; @@ -179,6 +179,18 @@ $cd = $schema->resultset("CD")->search(undef, { include_columns => [ 'artist.nam is($cd->title, 'Spoonful of bees', 'Correct CD returned with include'); is($cd->get_column('name'), 'Caterwauler McCrae', 'Additional column returned'); +# check if new syntax +columns also works for this +$cd = $schema->resultset("CD")->search(undef, { '+columns' => [ 'artist.name' ], join => [ 'artist' ] })->find(1); + +is($cd->title, 'Spoonful of bees', 'Correct CD returned with include'); +is($cd->get_column('name'), 'Caterwauler McCrae', 'Additional column returned'); + +# check if new syntax for +columns select specifiers works for this +$cd = $schema->resultset("CD")->search(undef, { '+columns' => [ {artist_name => 'artist.name'} ], join => [ 'artist' ] })->find(1); + +is($cd->title, 'Spoonful of bees', 'Correct CD returned with include'); +is($cd->get_column('artist_name'), 'Caterwauler McCrae', 'Additional column returned'); + # update_or_insert $new = $schema->resultset("Track")->new( { trackid => 100,