DQLs connect between unrelated objects?

Is it possible to bind DQL between unrelated objects using the WITH DQL statement? OR is a required compulsory relationship?

I have a unidirectional link to Category and CategorySubsription. Where CategorySubscription has many one-way relationships with a category. I want to grab a list of categories c and left to join CategorySubscription cs WITH cs.category_id = c.id AND cs.user_id = value.

Can I do it somehow?

+7
source share
2 answers

Starting with Doctrine version 2.3, you can, as stated in the blog .

It is also mentioned in docs if you know where to look. Scroll to the last example in the "15.2.4. DQL SELECT Examples" section:

Joins between entities without associations were not possible until version 2.4, where you can generate an arbitrary join with the following syntax: <?php $query = $em->createQuery('SELECT u FROM User u JOIN Blacklist b WITH u.email = b.email'); 

I know that he says "impossible until version 2.4", but it definitely works with 2.3!

+6
source

You can try using several from () methods and join conditions placed in where () or andWhere methods ()

-one
source

All Articles