E
E
Eugene Wolf2016-11-07 15:40:09
symfony
Eugene Wolf, 2016-11-07 15:40:09

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);

I understand that there is an option to implement the desired selection through your own methods in the repository, but I am sure that for such a banal task there should be a level solution to change / add 1 parameter , just like it is implemented in other Frameworks / ORM.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2016-11-07
@Wolfnsex

You need to set the fetch parameter to "EAGER"

/**
 * @ORM\OneToOne(targetEntity="App\Post" , fetch="EAGER")
 */

or
$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 question

Ask a Question

731 491 924 answers to any question