简体   繁体   English

COUNT = 0的Doctrine2 DQL问题

[英]Doctrine2 DQL issue with COUNT = 0

I have the following query so far: 到目前为止,我有以下查询:

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

I am trying to find a way to query all users who doesn't have a follower and whose follower is not my self (in this case my self is $user->getId() ). 我试图找到一种方法来查询所有没有关注者并且关注者不是我自己的用户(在这种情况下,我的自己是$user->getId() )。 How do I do so? 我该怎么做?

Try this 尝试这个

$shopQuery = $qb->from("BlahUserBundle:User", 'u')
            ->leftJoin(
                'u.followers',
                'followers',
                'on',
                'followers.id != :userId'
            )
            ->where('followers.id IS NULL')
            ->setParameter('userId', $user->getId());
$shopQuery->getQuery()->getResults();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM