having

Filter records using having

Using those additional parameters we need to adjust our where conditions

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 having object in the root object

$condition = array(
    'where' => array(
        'id' => array(
            'in' => array(1,2,3)
        )
    ),
    'order' => array(
        'id' => 'DESC'
    ),
    'group' => array(
        'id',
        'name'
    ),
    'having' => array(
        'id > 1',
        'id <= 5'
    )
)

$db->news->find($condition);

Last updated