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).

First the obvious solution:

$this->User->findAll('User.id NOT IN (1, 2, 3)');

And here the solution using the array syntax:

$this->User->findAll(array('NOT' => array('User.id' => array(1, 2, 3))));