Find where id is not in array of ids

2019-03-24 05:18发布

To find id whose value is equal to the id of an array of ids:

$this->YourModel->find('all', array(
    'conditions' => array(
        "YourModel.id" => array(1, 2, 3, 4)
    )
));

How I can do the opposite, find elements where the ids are different than an array of ids?

1条回答
劳资没心,怎么记你
2楼-- · 2019-03-24 05:28

This should work:

$this->YourModel->find('all', array(
    'conditions' => array(
        "NOT" => array( "YourModel.id" => array(1, 2, 3, 4) )
    )
));

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions

查看更多
登录 后发表回答