Doctrine2 DQL问题,COUNT = 0

时间:2013-11-15 05:34:00

标签: php mysql symfony orm doctrine-orm

到目前为止,我有以下查询:

   $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())。我该怎么做?

1 个答案:

答案 0 :(得分:1)

试试这个

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