groupBy
Group the records.
The adjustments are already introduced here.
Note:
// From
$condition = array('id' => 1);
// To
$condition = array(
'where' => array(
'id' => 1
)
)
// We can also use the other conditions
$condition = array(
'where' => array(
'id' => array(
'in' => array(1,2,3)
)
)
)
Usage:
Just add the group
object in the root object
// Using Order by
$condition = array(
'where' => array(
'id' => array(
'in' => array(1,2,3)
)
),
'order' => array(
'id' => 'DESC'
),
'group' => array(
'id',
'name'
)
)
// or multiple group by
$condition = array(
'where' => array(
'id' => array(
'in' => array(1,2,3)
)
),
'order' => array(
'id' => 'DESC',
'created_at' => 'ASC'
),
'group' => array(
'id',
'name'
)
)
$db->news->find($condition);
Last updated