Skip to content


DDC-734: Possibility to fetch all outstanding proxies of an Entity #5247

doctrinebot opened this Issue · 4 comments

2 participants


Jira issue originally created by user @beberlei:

For performance reasons (solving the N1 problem) it might be necessary to load all proxy instances of a given type:

$orders = $em->getRepository('Order')->findAll();
foreach ($orders AS $order) {
   $order->getCustomer()->getId(); // n</ins>1

However say we could do something like:

$orders = $em->getRepository('Order')->findAll();

foreach ($orders AS $order) {
   $order->getCustomer()->getId(); // n+1

This doesnt make too much sense in this case because we could use a fetch join with DQL. However you easily get to the point where you have a query like:

SELECT b, e, r, p FROM Bug b JOIN e 
JOIN b.reporter r JOIN b.products p ORDER BY b.created DESC

In this case the SQL generated is VERY huge and just the number of joins could cause an performance overhead. In general its better to keep the number of joins as small as possible, a solution here would optimize for the engineer and reporter being both instances of User:

$bugs = $em->createQuery("SELECT b, p FROM Bug b JOIN b.products p ORDER BY b.created DESC")->getResult();
$em->getUnitOfWork()->loadProxies("User"); // will load all engineers and reporters in one query

We could even make this nicer for using Queries:

$bugs = $em->createQuery("SELECT b, p FROM Bug b JOIN b.products p ORDER BY b.created DESC")
                        ->setQueryHint(Query::LOAD_PROXIES, array("User"))

Comment created by @beberlei:

Implemented, but in another semantical way. Batching of eager loads of FETCH=EAGER associations aswell as AbstactQuery::setFetchMode($className, $assocName, $fetchMode) function to set this case-by-case for DQL.


Issue was closed with resolution "Fixed"


Comment created by @guilhermeblanco:



Comment created by koc:

I cann't find commit/branch where it was fixed

@doctrinebot doctrinebot added this to the 2.1 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.