Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 + Doctrine2 is not caching results of joined entities
    primarykey
    data
    text
    <p>I am using Symfony 2.0.10 with Doctrine 2.1 and have rather simple query (see below), where I want to cache results with APC (version 3.1.7, enabled 1GB of memory for it) via <code>useResultCache(true, 600)</code> and keep hydration mode as <code>\Doctrine\ORM\Query::HYDRATE_OBJECT</code>.</p> <p>The problem is that Many-to-Many relations (<code>Doctrine\ORM\PersistentCollection</code>) don't get cached and every time when main query results are cached the joined entities are set to <code>null</code>. The same query is cached well in APC when I set hydration mode to <code>\Doctrine\ORM\Query::HYDRATE_ARRAY</code>, but it is not acceptable solution for me, because I can't redo many templates for this to work.</p> <p>Please suggest how can I cache all joined entities' properties in APC? Please don't point to documentation, because I think I have learned it by heart trying to solve this issue :)</p> <h3>CODE:</h3> <pre><code>$property = $em -&gt;createQueryBuilder() -&gt;select('p,u') -&gt;from('MyBundle:Property', 'p') -&gt;leftJoin('p.users', 'u') -&gt;where('p.id in (:id)') -&gt;setParameter('id', 123) -&gt;getQuery() -&gt;useResultCache(true, 60) -&gt;setHydrationMode(\Doctrine\ORM\Query::HYDRATE_OBJECT) -&gt;getResult(); </code></pre> <h3>User.php</h3> <pre><code>class User { /** * @ORM\ManyToMany(targetEntity="Property", mappedBy="users", cascade={"all"}, fetch="EAGER") */ protected $properties; } </code></pre> <h3>Property.php</h3> <pre><code>class Property { /** * @ORM\ManyToMany(targetEntity="User", inversedBy="properties", cascade={"all"}, fetch="EAGER") * @ORM\JoinTable(name="user_property", * joinColumns={@ORM\JoinColumn(name="property_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")} * ) */ protected $users; } </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.
 

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