Note that there are some explanatory texts on larger screens.

plurals
  1. POOne query per each entity
    primarykey
    data
    text
    <p>Imagine we have an ArrayCollection, containing several Doctrine Entities instance of Country. Also imagine that my method 'getName()' is, in fact, a one to many relation with several languages ( A2lixTranslation support )...</p> <p>The point is that this ArrayCollection is built from ElasticSearch service, so when I retrieve all these entities, iterate them and print their name, is just an extra query for every category.</p> <p>I don't really know how to manage this situation, so 150 extra queries is not mainainable...</p> <h2>Example Implementation</h2> <pre><code>$countries = // ArrayCollection of Countries, returned by any mapping system. foreach ($countries as $country) { /** * As name is an entity, uses lazy loading in every iteration * Because I get collection as it comes, I would like to retrieve * all names in one query. I thought about perform a DQL with a join * of all countries and their names, so Doctrine will catch'em all * but only catch my query and results, and do not identify retrieved * results with my collection, so is not working... */ $name = $country-&gt;getName(); echo $name; } // Could be nice do something like this... $countries = // ArrayCollection of Countries, returned by any mapping system. $queryBuilder = $this -&gt;getDoctrine() -&gt;getRepository('ProjectCoreBundle:Country') -&gt;createQueryBuilder('c'); /** * This query result should only add Cache with results */ $queryBuilder -&gt;select('c','t') -&gt;innerJoin('c.countryName','cn','WITH','c.id = cn.Country') -&gt;getQuery() -&gt;getResult(); foreach ($countries as $country) { /** * At this poing, as Name relation entity is already loaded and cached * lazy load will simply return object ( Any query is performed ) */ $name = $country-&gt;getName(); echo $name; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload