orderBy
Sort records by asc or desc order.
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 order
object in the root object
// Using Order by
$condition = array(
'where' => array(
'id' => array(
'in' => array(1,2,3)
)
),
'order' => array(
'id' => 'DESC'
)
)
// or multiple order by
$condition = array(
'where' => array(
'id' => array(
'in' => array(1,2,3)
)
),
'order' => array(
'id' => 'DESC',
'created_at' => 'ASC'
)
)
$db->news->find($condition);
Last updated