Implement GROUP BY clause functionality

This commit is contained in:
Alexander Fuhr 2014-10-06 11:34:04 +02:00
parent e96065e065
commit 97d2a920db

View File

@ -59,6 +59,13 @@ class DbQuery extends SimpleQuery
*/ */
protected $count; protected $count;
/**
* GROUP BY clauses
*
* @var string|array
*/
protected $group;
protected function init() protected function init()
{ {
$this->db = $this->ds->getDbAdapter(); $this->db = $this->ds->getDbAdapter();
@ -100,6 +107,10 @@ class DbQuery extends SimpleQuery
} }
} }
if ($this->group) {
$select->group($this->group);
}
$select->columns($this->columns); $select->columns($this->columns);
$this->applyFilterSql($select); $this->applyFilterSql($select);
@ -300,4 +311,17 @@ class DbQuery extends SimpleQuery
{ {
return (string) $this->getSelectQuery(); return (string) $this->getSelectQuery();
} }
/**
* Add a GROUP BY clause
*
* @param string|array $group
*
* @return $this
*/
public function group($group)
{
$this->group = $group;
return $this;
}
} }