[Bast-commits] r6352 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t/count

arcanez at dev.catalyst.perl.org arcanez at dev.catalyst.perl.org
Wed May 20 15:06:51 GMT 2009


Author: arcanez
Date: 2009-05-20 15:06:50 +0000 (Wed, 20 May 2009)
New Revision: 6352

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/trunk/t/count/distinct.t
Log:
fix for sql functions in group_by

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-05-20 15:04:17 UTC (rev 6351)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-05-20 15:06:50 UTC (rev 6352)
@@ -2610,7 +2610,7 @@
 
   }
 
-  $attrs->{group_by} ||= $attrs->{select}
+  $attrs->{group_by} ||= [ grep { !ref($_) || (ref($_) ne 'HASH') } @{$attrs->{select}} ]
     if delete $attrs->{distinct};
   if ( $attrs->{order_by} ) {
     $attrs->{order_by} = (

Modified: DBIx-Class/0.08/trunk/t/count/distinct.t
===================================================================
--- DBIx-Class/0.08/trunk/t/count/distinct.t	2009-05-20 15:04:17 UTC (rev 6351)
+++ DBIx-Class/0.08/trunk/t/count/distinct.t	2009-05-20 15:06:50 UTC (rev 6352)
@@ -13,7 +13,7 @@
 
 eval "use DBD::SQLite";
 plan skip_all => 'needs DBD::SQLite for testing' if $@;
-plan tests => 19;
+plan tests => 21;
 
 # The tag Blue is assigned to cds 1 2 3 and 5
 # The tag Cheesy is assigned to cds 2 4 and 5
@@ -71,11 +71,8 @@
 $rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => [ qw/tag cd/ ] });
 is($rs->count, 7, 'Count with literal SQL and multiple group_by');
 
-$rs = $schema->resultset('Tag')->search({}, {
-  select => { length => 'tag' },
-  distinct => 1
-});
-is($rs->count, 3, 'Count by distinc result of function');
+$rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { '+select' => { max => 'tagid' }, distinct => 1 });
+is($rs->count, 4, 'Count with +select aggreggate');
 
 my @warnings;
 {
@@ -86,3 +83,5 @@
 is(@warnings, 1, 'expecteing warn');
 
 dies_ok(sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first }, 'expecting to die');
+dies_ok(sub { my $count = $schema->resultset('Tag')->search({}, { '+select' => \'tagid AS tag_id', distinct => 1 })->count }, 'expecting to die');
+dies_ok(sub { my $count = $schema->resultset('Tag')->search({}, { select => { length => 'tag' }, distinct => 1 })->count }, 'expecting to die');




More information about the Bast-commits mailing list