Answer the question
In order to leave comments, you need to log in
How to get non-reciprocal subscriptions?
So I have 2 tables:
User
followers | OneToMany | mappedBy="followed"
following | OneToMany | mappedBy="follower"
Follow
followed | ManyToOne | inversedBy="followers"
follower | ManyToOne | inversedBy="following"
$qb ->join('u.following', 'follow')
->where('follow.followed = :user')
->setParameter('user', $user)
$qb ->join('u.followers', 'follow')
->where('follow.follower = :user')
->setParameter('user', $user)
$qb ->join('u.followers', 'fs')
->join('u.following','fg')
->where('fs.follower = :user')
->andWhere('fg.followed = :user')
->setParameter('user', $user)
Answer the question
In order to leave comments, you need to log in
It doesn't work, because you have a request for mutual subscriptions of the curve itself, and you don't understand how join works. The problem you have is in the 2nd join. To paint laziness, so briefly.
As a result of all joins, you get a table in which each follower for the user is compared with following. It is simply impossible to choose non-reciprocal subscriptions from such a pile of data.
For the 2nd requests, you need to join not all of the following, but only those who have followed = fs.follower. Moreover, use left join and then check in where for null.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question