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 useResultCache(true, 600)
and keep hydration mode as \Doctrine\ORM\Query::HYDRATE_OBJECT
.
The problem is that Many-to-Many relations (Doctrine\ORM\PersistentCollection
) don't get cached and every time when main query results are cached the joined entities are set to null
. The same query is cached well in APC when I set hydration mode to \Doctrine\ORM\Query::HYDRATE_ARRAY
, but it is not acceptable solution for me, because I can't redo many templates for this to work.
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 :)
$property = $em
->createQueryBuilder()
->select('p,u')
->from('MyBundle:Property', 'p')
->leftJoin('p.users', 'u')
->where('p.id in (:id)')
->setParameter('id', 123)
->getQuery()
->useResultCache(true, 60)
->setHydrationMode(\Doctrine\ORM\Query::HYDRATE_OBJECT)
->getResult();
class User {
/**
* @ORM\ManyToMany(targetEntity="Property", mappedBy="users", cascade={"all"}, fetch="EAGER")
*/
protected $properties;
}
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;
}
Here is the Doctrine JIRA issue related to a caching issue which is the closest to the problem's description:
http://www.doctrine-project.org/jira/browse/DDC-217
https://github.com/doctrine/doctrine2/issues/2861
My opinion is that point is fixed in Doctrine 2.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With