From: Cory G Watson Date: Thu, 23 Apr 2009 20:49:04 +0000 (+0000) Subject: Fix busted get_column when using +select (and friends) X-Git-Tag: v0.08101~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=121068ec48336496a7ba216517c8caff27ceb99a Fix busted get_column when using +select (and friends) --- diff --git a/Changes b/Changes index 3967221..324db43 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for DBIx::Class + - Fix +select, +as, +columns and include_columns being stripped from + ->get_columns (gphat) + 0.081000 2009-04-19 11:39:35 (UTC) - Todo out the register_extra_source test until after shipping diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index fbedf88..596df7c 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -38,7 +38,7 @@ sub new { $class = ref $class if ref $class; my $new_parent_rs = $rs->search_rs; # we don't want to mess up the original, so clone it my $attrs = $new_parent_rs->_resolved_attrs; - $new_parent_rs->{attrs}->{$_} = undef for qw(prefetch include_columns +select +as); # prefetch, include_columns, +select, +as cause additional columns to be fetched + $new_parent_rs->{attrs}->{prefetch} = undef; # prefetch cause additional columns to be fetched # If $column can be found in the 'as' list of the parent resultset, use the # corresponding element of its 'select' list (to keep any custom column diff --git a/t/76select.t b/t/76select.t index 4325a70..ca6a5e9 100644 --- a/t/76select.t +++ b/t/76select.t @@ -8,7 +8,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 12; +plan tests => 13; my $rs = $schema->resultset('CD')->search({}, { @@ -28,6 +28,16 @@ $rs = $schema->resultset('CD')->search({}, 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'); +# Tests a regression in ResultSetColumn wrt +select +my $rs = $schema->resultset('CD')->search(undef, + { + '+select' => [ \'COUNT(*) AS year_count' ], + order_by => 'year_count' + } +); +my @counts = $rs->get_column('cdid')->all; +ok(scalar(@counts), 'got rows from ->all using +select'); + $rs = $schema->resultset('CD')->search({}, { '+select' => [ \ 'COUNT(*)', 'title' ],