Subject: | DBIC does not handle ->count() and { group_by => [ ] } correctly (properly?) |
$rs->resultset('table')->search({}, { group_by => [ 'col1', 'col2' ]
})->count();
makes
SELECT COUNT( DISTINCT( col1, col2 ) ) FROM table me:
DBI Exception: DBD::Pg::st execute failed: ERROR: could not identify an
equality operator for type record [for Statement "SELECT COUNT(
DISTINCT( col1, col2 ) ) FROM table me"]
PATCH:
Index: ResultSet.pm
===================================================================
--- ResultSet.pm (revision 5736)
+++ ResultSet.pm (working copy)
@@ -1128,9 +1128,9 @@
sub _count { # Separated out so pager can get the full count
my $self = shift;
- my $select = { count => '*' };
+ my $attrs = { %{$self->_resolved_attrs} };
+ my $from = $attrs->{from};
- my $attrs = { %{$self->_resolved_attrs} };
if (my $group_by = delete $attrs->{group_by}) {
delete $attrs->{having};
my @distinct = (ref $group_by ? @$group_by : ($group_by));
@@ -1145,13 +1145,16 @@
}
}
}
-
- $select = { count => { distinct => \@distinct } };
+ $attrs->{select} = $group_by;
+ my $from_rs = (ref $self)->new($self->result_source, $attrs);
+ $from = { 'as_query' => ${$from_rs->as_query}->[0] };
}
- $attrs->{select} = $select;
+ $attrs->{select} = { count => '*' };
$attrs->{as} = [qw/count/];
+ $attrs->{from} = $from;
+
# offset, order by and page are not needed to count. record_filter is
cdbi
delete $attrs->{$_} for qw/rows offset order_by page pager
record_filter/;
Subject: | ResulSet-count-fix.patch |
Index: ResultSet.pm
===================================================================
--- ResultSet.pm (revision 5736)
+++ ResultSet.pm (working copy)
@@ -1128,9 +1128,9 @@
sub _count { # Separated out so pager can get the full count
my $self = shift;
- my $select = { count => '*' };
+ my $attrs = { %{$self->_resolved_attrs} };
+ my $from = $attrs->{from};
- my $attrs = { %{$self->_resolved_attrs} };
if (my $group_by = delete $attrs->{group_by}) {
delete $attrs->{having};
my @distinct = (ref $group_by ? @$group_by : ($group_by));
@@ -1145,13 +1145,16 @@
}
}
}
-
- $select = { count => { distinct => \@distinct } };
+ $attrs->{select} = $group_by;
+ my $from_rs = (ref $self)->new($self->result_source, $attrs);
+ $from = { 'as_query' => ${$from_rs->as_query}->[0] };
}
- $attrs->{select} = $select;
+ $attrs->{select} = { count => '*' };
$attrs->{as} = [qw/count/];
+ $attrs->{from} = $from;
+
# offset, order by and page are not needed to count. record_filter is cdbi
delete $attrs->{$_} for qw/rows offset order_by page pager record_filter/;