Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a DQL select statement to search some, but not all the entities in a single table inheritance table

Tags:

doctrine-orm

So I have 3 entities within one table. I need to be able to search 2 out of the 3 entities in one select statement, but I'm not sure how to do this.

like image 447
blacktie24 Avatar asked Sep 21 '11 18:09

blacktie24


1 Answers

Use the INSTANCE OF operator in your dql query like this (where User is your base class):

$em->createQuery('
    SELECT u 
    FROM Entity\User u 
    WHERE (u INSTANCE OF Entity\Manager OR u INSTANCE OF Entity\Customer)
');

Doctrine translates this in the sql query in a WHERE user.type = '...' condition.

See here for more details on the dql query syntax.

like image 133
Max Avatar answered Sep 19 '22 18:09

Max