I have a query in entity repository with a ManyToMany other entity : Meeting have many Users
This is my qb :
$userIds = [2];
$qb = $this->createQueryBuilder('m')
->leftJoin('m.users', 'mu')
->leftJoin('mu.user', 'u')
->where('u.id IN (:ids)')
->setParameter('id', $userIds);
This work well, if i have a meeting with two users and the user with id=2 is in, the query give the full result with two users.
My problem is that i have many db queries (84) when i display users informations, so i use addSelect like this :
$userIds = [2];
$qb = $this->createQueryBuilder('m')
->leftJoin('m.users', 'mu')
->addSelect('mu')
->leftJoin('mu.user', 'u')
->addSelect('u')
->where('u.id IN (:ids)')
->setParameter('id', $userIds);
Great ! i have now only 16 queries for display informations. but my query return only the user with id=2 in my meeting with two users ???
I have the same problem if i keep only the addSelect('mu'). I think the addSelect() is not execute in users who are not my search.
How retrieve the entire results with addSelect() to reduce queries ?
Thanks for help