I have three objects connected in this way:
Don't worry, I made associations using annotations, but I thought the next mix would be easier / cleaner to identify my problem.
Post @ORM\ManyToOne(targetEntity="User", fetch="EAGER") - author User @ORM\OneToOne(targetEntity="Vip", mappedBy="user", fetch="EAGER") - vip Vip # Notice that the primary key of vip is a foreign key on User primary @ORM\id @ORM\OneToOne(targetEntity="User", inversedBy="peliqan", fetch="EAGER") @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) - user
As you can see, everything is set up to be impatient.
What I need?
I would like to receive message sets along with and Users & Vip ONLY using a single request . (see edit)
Right now, for each message entry, I get one additional request:
SELECT t0.valid AS valid_1, ... FROM vip t0 INNER JOIN user t10 ON t0.user_id = t10.id WHERE t0.user_id = ?
when:
I'm doing this
$results = $qb ->select('ps') ->leftJoin('ps.author','u')->addSelect('u') ->add('where', $qb->expr()->in('ps.id', $ids)) ->getQuery()->getResult();
and even when I try to apply FETCH_EAGER mode like this
->getQuery() ->setFetchMode('AppBundle\Entity\User', 'vip', ClassMetadata::FETCH_EAGER) ->getResult();
Note:
I managed to get rid of the extra request enforcingQuery::HYDRATE_ARRAY when calling getResult() .
Requests disappeared, which saved a third from the original time.
The disadvantage here is that when you remove the association as an array, I could no longer use Symfony\Component\Serializer\Annotation\Groups Groups to filter the properties of objects and had to manually edit the result set to remove / convert some values.
EDIT
The wilt response is appropriate for the original message. I did not solve my problem correctly. I said that I wanted to get Vip information because I thought it was a good way to get rid of the extra request that I am talking about above. Actually, I don't need information about Vip, but omitting ->leftJoin('u.vip','v')->addSelect('v') makes the doctrine issue an additional request that collects Vip information! Is there a way to prevent the doctrine of fulfilling this request?