From 52de52a17ad349bb2bbae3842cb1ca7f9adeb16e Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Tue, 3 Jun 2014 20:06:56 +0400 Subject: [PATCH] Fix count --- model/SqlCriteria.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/model/SqlCriteria.php b/model/SqlCriteria.php index a0e645d..67b9a3e 100644 --- a/model/SqlCriteria.php +++ b/model/SqlCriteria.php @@ -83,9 +83,8 @@ class SqlCriteria { $this->defineJoinExpressions(); $sql_expression_backup = $this->sql_expression; - if ($this->sql_expression) { - $select = $this->model->getDb()->selectExpr($this->select, $this->distinct); - $this->sql_expression = str_replace($select, 'COUNT(*) as count', $this->sql_expression); + if ($this->sql_expression && !strstr('COUNT(*)', $this->sql_expression)) { + $this->sql_expression = preg_replace('#^SELECT .+ FROM#', 'SELECT COUNT(*) as count FROM', $this->sql_expression); } else { $this->sql_expression = 'SELECT COUNT(*) as count FROM :table'; }