From: Brian Cassidy Date: Thu, 27 Sep 2007 18:37:15 +0000 (+0000) Subject: ResultSetColumn::func() now returns all results if called in list context X-Git-Tag: v0.08010~63 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5d62876f5fe86bc1b3a11a571074164bcce27e7b;p=dbsrgits%2FDBIx-Class.git ResultSetColumn::func() now returns all results if called in list context --- diff --git a/Changes b/Changes index 85ccfb8..85e824d 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,8 @@ Revision history for DBIx::Class - When adding relationships, it will throw an exception if you get the foreign and self parts the wrong way round in the condition + - ResultSetColumn::func() now returns all results if called in list + context; this makes things like func('DISTINCT') work as expected 0.08007 2007-09-04 19:36:00 - patch for Oracle datetime inflation (abram@arin.net) diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index f93cbdd..68cc4e0 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -175,8 +175,13 @@ value. Produces the following SQL: sub func { my ($self,$function) = @_; - my ($row) = $self->{_parent_resultset}->search(undef, {select => {$function => $self->{_column}}, as => [$self->{_column}]})->cursor->next; - return $row; + my $cursor = $self->{_parent_resultset}->search(undef, {select => {$function => $self->{_column}}, as => [$self->{_column}]})->cursor; + + if( wantarray ) { + return map { $_->[ 0 ] } $cursor->all; + } + + return ( $cursor->next )[ 0 ]; } 1; diff --git a/t/88result_set_column.t b/t/88result_set_column.t index 08828af..ef4912b 100644 --- a/t/88result_set_column.t +++ b/t/88result_set_column.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 9; +plan tests => 10; my $cd; my $rs = $cd = $schema->resultset("CD")->search({}); @@ -17,6 +17,8 @@ my $rs_year = $rs->get_column('year'); is($rs_title->next, 'Spoonful of bees', "next okay"); +is_deeply( [ sort $rs_year->func('DISTINCT') ], [ 1997, 1998, 1999, 2001 ], "wantarray context okay"); + my @all = $rs_title->all; cmp_ok(scalar @all, '==', 5, "five titles returned");