Исправление ошибки в SqlCriteria.count() - дублирующееся COUNT(COUNT( * во внутреннем sql-запросе

This commit is contained in:
2014-09-29 15:59:55 +04:00
parent bccd018530
commit b6e002f5a8
2 changed files with 6 additions and 5 deletions

View File

@ -226,12 +226,12 @@ abstract class SqlModel extends Model
return new SqlResultProvider($result);
}
public function count($select = 'x.count', $where, $heaving = null, $group_by = null, $sql_expression = null, $sql_expression_params = array(), $cache_key = null)
public function count($select_parent_query = 'x.count', $where, $heaving = null, $group_by = null, $sql_expression = null, $sql_expression_params = array(), $cache_key = null)
{
$where = $this->db->whereExpr($where);
$group_by = $this->db->groupByExpr($group_by);
$result = $this->query(
'SELECT ' . $select . ' FROM (' .
'SELECT ' . $select_parent_query . ' FROM (' .
(($sql_expression) ? $sql_expression : ('SELECT * FROM ' . $this->identify($this->table())))
. (($where) ? (' WHERE ' . $where) : '')
. (($group_by) ? (' GROUP BY ' . $group_by) : '') . ') AS x',