Add group by support in sql criteria.

This commit is contained in:
Alexander Demidov
2013-10-29 16:42:33 +04:00
parent d019ae2450
commit 4878b32641
3 changed files with 39 additions and 1 deletions

View File

@ -8,6 +8,8 @@ class SqlCriteria
private $where = array();
private $group_by = array();
private $order = array('sort' => array(), 'order' => array());
private $limit = '';
@ -38,7 +40,7 @@ class SqlCriteria
*/
public function find()
{
return $this->model->find($this->select, $this->distinct, $this->where, $this->order, $this->limit, null, null, $this->sql_expression, $this->sql_expression_params);
return $this->model->find($this->select, $this->distinct, $this->where, $this->order, $this->limit, null, $this->group_by, $this->sql_expression, $this->sql_expression_params);
}
public function count()
@ -96,6 +98,16 @@ class SqlCriteria
return $this->whereNotIn($field, $value);
}
public function groupBy($fields)
{
if (is_array($fields)) {
$this->group_by = $this->group_by + $fields;
} else {
$this->group_by[] = $fields;
}
return $this;
}
/**
* @param $field string Field @ex 'field'
* @param $order_desc bool Descendant sort direction