Answer the question
In order to leave comments, you need to log in
Symfony / Doctrine 2, how to implement link preloading (single request)?
Good day dear! I'm learning Doctrine2, implemented Bidirectional communication as described here .
Everything works fine, but I'm confused by the fact that every time a connection is accessed - Doctrine2 generates a new query, fetching the appropriate data.
How to implement automatic loading of all (data) links in 1 request?
That is, replace 50 requests of the form: SELECT xxx FROM yyy WHERE zzz_id = 1, 2, 3 .. 50;
with 1 request of the form:
SELECT xxx FROM yyy WHERE zzz_id IN (1, 2, 3, .. 50);
Answer the question
In order to leave comments, you need to log in
You need to set the fetch parameter to "EAGER"
/**
* @ORM\OneToOne(targetEntity="App\Post" , fetch="EAGER")
*/
$query = $em->createQuery("SELECT u FROM App\User u");
$query->setFetchMode("App\User", "posts", \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER);
$query->execute();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question