How to create a NOT IN where Doctrine_Query element?

I am developing in symfony 1.4 using Doctrine ORM. I cannot create a NOT IN where clause using an array with identifiers. This is my code:

$results = Doctrine_Query::create()
  ->from('Asset a')
  ->where('a.id NOT IN (?)', implode(',', $ids))
  ->execute();

The sql for this query that is generated is as follows:

WHERE (a.id NOT IN ('1,5,6,7,8,9,10,11,12,13,14,15,17,18,20,24,25,26,29,30,28'))

As you can see, array processing is filled with identifiers of type string. I also tried without an implode array, but getting this error:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

Array identifiers containing excluded identifiers are simple numeric.

I cannot find out what is the correct syntax for this sentence. Thanks

+3
source share
1 answer

You should use whereNotIn( old document, but still fine ).

$results = Doctrine_Query::create()
  ->from('Asset a')
  ->whereNotIn('a.id', $ids)
  ->execute();
+2
source

All Articles