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