$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
}
else {
- # otherwise we intialise select & as
+ # otherwise we intialise select & as to empty
$attrs->{select} = [];
$attrs->{as} = [];
}
my $schema = DBICTest->init_schema();
-plan tests => 84;
+plan tests => 88;
eval { require DateTime::Format::MySQL };
my $NO_DTFM = $@ ? 1 : 0;
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,