到目前为止,我有以下查询:
$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()
)。我该怎么做?
答案 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();