From: Peter Rabbitson Date: Wed, 29 Oct 2008 11:18:44 +0000 (+0000) Subject: Minor chaining patch + test by Norbert Buchmuller (chaining needs a massive cleanup... X-Git-Tag: v0.08240~293 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=218aa968674450b76e0675074b1c8a1a8afd6a3a;p=dbsrgits%2FDBIx-Class.git Minor chaining patch + test by Norbert Buchmuller (chaining needs a massive cleanup, delayed until next release) --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 42dade5..bd615d3 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -200,7 +200,7 @@ sub search_rs { my $new_attrs = { %{$our_attrs}, %{$attrs} }; # merge new attrs into inherited - foreach my $key (qw/join prefetch/) { + foreach my $key (qw/join prefetch +select +as/) { next unless exists $attrs->{$key}; $new_attrs->{$key} = $self->_merge_attr($our_attrs->{$key}, $attrs->{$key}); } diff --git a/t/76select.t b/t/76select.t new file mode 100644 index 0000000..213ecba --- /dev/null +++ b/t/76select.t @@ -0,0 +1,44 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +plan tests => 7; + +my $rs = $schema->resultset('CD')->search({}, + { + '+select' => \ 'COUNT(*)', + '+as' => 'count' + } +); +lives_ok(sub { $rs->first->get_column('count') }, 'additional count rscolumn present'); +dies_ok(sub { $rs->first->get_column('nonexistent_column') }, 'nonexistant column requests still throw exceptions'); + +$rs = $schema->resultset('CD')->search({}, + { + '+select' => [ \ 'COUNT(*)', 'title' ], + '+as' => [ 'count', 'addedtitle' ] + } +); +lives_ok(sub { $rs->first->get_column('count') }, 'multiple +select/+as columns, 1st rscolumn present'); +lives_ok(sub { $rs->first->get_column('addedtitle') }, 'multiple +select/+as columns, 2nd rscolumn present'); + +$rs = $schema->resultset('CD')->search({}, + { + '+select' => [ \ 'COUNT(*)', 'title' ], + '+as' => [ 'count', 'addedtitle' ] + } +)->search({}, + { + '+select' => 'title', + '+as' => 'addedtitle2' + } +); +lives_ok(sub { $rs->first->get_column('count') }, '+select/+as chained search 1st rscolumn present'); +lives_ok(sub { $rs->first->get_column('addedtitle') }, '+select/+as chained search 1st rscolumn present'); +lives_ok(sub { $rs->first->get_column('addedtitle2') }, '+select/+as chained search 3rd rscolumn present');