Yesterday, moeffju asked in a comment to the post “Using an IN list in a condition” how to use NOT IN in SQL queries generated by CakePHP. A good question as the solution is not that obvious (at least if you use the array syntax for conditions).
Here the solution for older CakePHP versions:
$this->User->findAll('User.id NOT IN (1, 2, 3)'); $this->User->findAll(array('NOT' => array('User.id' => array(1, 2, 3))));
The findAll() method has been removed in newer CakePHP versions (1.3.x). The solution is now:
$this->User->find('all', array('conditions' => array('NOT' => array('User.id' => array(1, 2, 3)))));
Update 2010-10-20: Adapted code snippet for CakePHP 1.3.x