Find where id is not in array of ids

Martin picture Martin · Jan 24, 2013 · Viewed 33.9k times · Source

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?

Answer

BigBagel picture BigBagel · Jan 24, 2013

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