2012-01-30 59 views
7

使用WITH DQL运算符可以在不相关的实体之间建立DQL连接吗? OR是绝对必要的关系吗?不相关实体之间的DQL连接?

我与Category和CategorySubsription有单向关系。其中CategorySubscription与Category具有多对一的单向关系。我想抓取Categories c的列表,并用cs.category_id = c.id和cs.user_id = value左连接CategorySubscription cs。

我能以某种方式做到这一点吗?

回答

-1

您可以尝试使用多种来自()方法,并加入置于条件,其中()或andWhere方法()

6

与学说2.3,你可以版本开始,如在blog提及。

docs中也有提及,如果你知道在哪里看。向下滚动到下的最后一个例子“15.2.4 DQL选择的例子。”:

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'); 

我知道它说:“不可能的,直到2.4版”,但它肯定工程启动2.3!

+0

非常感谢,为我工作。 – Daniel 2016-07-29 13:03:54