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'; }