Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find where id is not in array of ids

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?

like image 356
Martin Avatar asked Jan 24 '13 18:01

Martin


1 Answers

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

like image 55
BigBagel Avatar answered Oct 21 '22 22:10

BigBagel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!