blacktie24 blacktie24 - 1 year ago 115
PHP Question

Doctrine 2: how to write a DQL select statement to search some, but not all the entities in a single table inheritance table

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. Any advice would be greatly appreciated! Cheers!

Max Max
Answer Source

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

    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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download