1

I want to use where not In clause in doctrine

I did it like this:

$q->select('u.id')
->add('from', $from)
->Join('Entities\User','u','with','evt_vstr.user = u.id')
->where('evt_vstr.event = ?1')
->andwhere('u.designation= ?2')
->andwhere('u.id notIN (SELECT sender FROM Entities\Connect)')
ORTHIS  ->andwhereNotIn('i.id',$connect_id)  
->setParameter(1,$content['event_id'])
->setParameter(2,$content['designation'])
->setFirstResult($i)
->setMaxResults($max_result);

but its throw an error:

PHP Fatal error:  Uncaught exception 'Doctrine\\ORM\\Query\\QueryException' with message 'SELECT u.id FROM Entities\\EventVisitor evt_vstr INNER JOIN Entities\\User u WITH evt_vstr.user = u.id WHERE evt_vstr.event = ?1 AND u.designation= ?2 AND u.id notIN ('SELECT sender FROM Entities\\Connect')'

and when I write this as follow

->andwhereNotIn('u.id', array(1,2,3,4,5)')

then it gives the following error

PHP Fatal error:  Call to undefined method Doctrine\\ORM\\QueryBuilder::andwhereNotIn()

I read this here: doctrine how to write WhereIn() with another sql query inside

How can I do that ?

sjagr, Yann Eugoné

Community
  • 1
  • 1
Sunil Kumar
  • 311
  • 1
  • 5
  • 16
  • Have a look at this http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html. **IN() Expression** – smarber Nov 24 '14 at 11:30
  • Try `not IN` instead of `notIN`. – A.L Nov 24 '14 at 12:17
  • I found nothing about IN or NOT IN here [smarber](http://stackoverflow.com/users/1507546/smarber) – Sunil Kumar Nov 24 '14 at 12:25
  • i tried this also ->andwhereNotIn('u.id',$connect_id) saying undefined methode – Sunil Kumar Nov 24 '14 at 12:40
  • Go to http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html, then `CTRL-F` and type `IN() Expression` – smarber Nov 24 '14 at 13:02
  • yes it is but its in simple sql query not using createqueryBuilder() [smarber](http://stackoverflow.com/users/1507546/smarber) like this SELECT u FROM CmsUser u WHERE u.id IN (1, 2) – Sunil Kumar Nov 24 '14 at 13:08
  • You need use EXPRESSION in your DQL then Doctrine will catch `expr()->notIn($x, $y)`; furthermore, for the second `SELECT` you need to get a separate DQL by using queryBuilder then you need to use it as second param as `->notIn($x, $DQL)`. Take a look at http://doctrine-orm.readthedocs.org/en/latest/reference/query-builder.html#the-expr-class for more info – Javad Nov 24 '14 at 15:11
  • there is a description about whereNotIN() something like Convenience/proxy method for whereNotIn(). at http://symfony.com/legacy/doc/doctrine/1_2/en/06-Working-With-Data . what does it mean ? i am unable to find anything about this [Javad](http://stackoverflow.com/users/3348750/javad),[smarber](http://stackoverflow.com/users/1507546/smarber) – Sunil Kumar Nov 25 '14 at 06:27

0 Answers0