Add group by support in sql criteria.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user