【发布时间】:2013-11-28 10:37:07
【问题描述】:
到目前为止,我有以下查询:
$shopQuery = $qb->select('DISTINCT u')
->from("BlahUserBundle:User", 'u')
->innerJoin('u.followers', 'followers')
->andWhere('followers.id != :userId')
->setParameter('userId', $user->getId())
->orWhere('') //or where those user who doesn't have a follower yet
//->setMaxResults(5)
;
我正在尝试找到一种方法来查询所有没有追随者且追随者不是我自己的用户(在这种情况下,我的自己是$user->getId())。我该怎么做?
【问题讨论】:
-
如果您使用innerJoin,您将无法获得您想要的结果,因为如果用户没有关注者,您将无法获得该行。我认为您需要一个子查询。让我考虑一下:)
-
@Pi Wi 是对的,但您可以用左连接替换内连接以匹配两个结果。
标签: php mysql symfony orm doctrine-orm