I am using Symfony 2.8 / Doctrine ORM 2.5.2.
I have 2 objects, GalleryOneToManyFile
class Gallery
{
private $files;
}
I see 2 things in the documentation.
First, OneToMany relationships now have a parameter fetch=EAGER( specified here ). This was not in previous versions.
Secondly, the manual installation for this selection of the method in the request does not seem to be for OneToMany, but I do not know if the documentation is updated as indicated:
Changing the sampling mode during a query is possible only for one-to-one and many-to-one relationships.
I tried both, anyway, here is my query:
public function findWithEager()
{
$qb = $this->createQueryBuilder('g');
$query = $qb->getQuery();
$query->setFetchMode("CommonBundle\\Entity\\Gallery", "files", ClassMetadata::FETCH_EAGER);
return $query->getResult();
}
But when I do this:
foreach ($galleryRepository->findWithEager() as $gallery) {
foreach ($gallery->getFiles() as $file) {
$file->getId();
}
}
Then I received 1 + n requests. The first one is SELECT * FROM Gallery, and the next n -SELECT * FROM File WHERE id = :galleryId
, Doctrine 1 + 1 , - SELECT * FROM File WHERE id IN (:galleryListIds)
- ? Doctrine?
:
"--" fetch = "EAGER" , , indexBy.
, .
, !