From 5a5bdef2ba0e28c941e3646bca98617fe07346db Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 15 Dec 2008 03:12:36 +0000 Subject: [PATCH] BUGFIX: Fixed bug in SQLQuery::unlimitedRowCount() when used with grouped queries, that should fix a lot of pagination situations. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@68940 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/SQLQuery.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/model/SQLQuery.php b/core/model/SQLQuery.php index dcf389888..98065acd8 100755 --- a/core/model/SQLQuery.php +++ b/core/model/SQLQuery.php @@ -445,7 +445,16 @@ class SQLQuery extends Object { * * TODO Respect HAVING and GROUPBY, which can affect the result-count */ - function unlimitedRowCount( $column = "*" ) { + function unlimitedRowCount( $column = null) { + // Choose a default column + if($column == null) { + if($this->groupby) { + $column = 'DISTINCT ' . implode(", ", $this->groupby); + } else { + $column = '*'; + } + } + $clone = clone $this; $clone->select = array("count($column)"); $clone->limit = null;