1

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()). How do I do so?

2
  • 1
    If you use an innerJoin you won't get the result you want because, if a user doesn't have a follower you won't get that row. I think you need a subQuery for this. Let me think about it :) Commented Nov 15, 2013 at 8:57
  • @Pi Wi is right, but you may replace your inner join by a left join to match both results. Commented Nov 15, 2013 at 9:06

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.