BUGFIX: Make TableListField rely on SQLQuery for its count-generation.

BUGFIX: Make SQLQuery return an appropriate count if a HAVING clause is used. (from r95814)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98094 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-02-04 00:52:43 +00:00
parent afe433c9ab
commit ce4067608c
2 changed files with 7 additions and 16 deletions

View File

@ -426,6 +426,12 @@ class SQLQuery {
* TODO Respect HAVING and GROUPBY, which can affect the result-count
*/
function unlimitedRowCount( $column = null) {
// we can't clear the select if we're relying on its output by a HAVING clause
if(count($this->having)) {
$records = $this->execute();
return $records->numRecords();
}
// Choose a default column
if($column == null) {
if($this->groupby) {

View File

@ -852,23 +852,8 @@ JS
if($this->customSourceItems) {
return $this->customSourceItems->Count();
}
$countQuery = $this->getQuery();
$countQuery->orderby = array();
$baseClass = ClassInfo::baseDataClass($this->sourceClass);
// we can't clear the select if we're relying on its output by a HAVING clause
if(count($countQuery->having) || count($countQuery->groupby)) {
$records = $countQuery->execute();
// TODO figure out how to use COUNT and GROUBY together to produce a single rowcount
$this->totalCount = $records->numRecords();
} else {
$countQuery->select = array();
$countQuery->groupby = array();
$countQuery->select[] = "COUNT(DISTINCT \"{$baseClass}\".\"ID\") AS \"TotalCount\"";
$records = $countQuery->execute();
$record = $records->nextRecord();
$this->totalCount = $record['TotalCount'];
}
$this->totalCount = $this->getQuery()->unlimitedRowCount();
return $this->totalCount;
}