From d57ecc12c06674c3fb114c0e77653e746340fede Mon Sep 17 00:00:00 2001 From: Guido Contreras Woda Date: Wed, 11 Nov 2015 12:09:13 -0300 Subject: [PATCH] Collection cache key is built differently on read than on write --- .../Entity/AbstractEntityPersister.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index e71f8e66e..ef95ab772 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -553,7 +553,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister if ($hasCache) { $ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); - $key = new CollectionCacheKey($assoc['sourceEntity'], $assoc['fieldName'], $ownerId); + $key = $this->buildCollectionCacheKey($assoc, $ownerId); $list = $persister->loadCollectionCache($coll, $key); if ($list !== null) { @@ -588,7 +588,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister if ($hasCache) { $ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); - $key = new CollectionCacheKey($assoc['sourceEntity'], $assoc['fieldName'], $ownerId); + $key = $this->buildCollectionCacheKey($assoc, $ownerId); $list = $persister->loadCollectionCache($coll, $key); if ($list !== null) { @@ -637,4 +637,17 @@ abstract class AbstractEntityPersister implements CachedEntityPersister $this->persister->refresh($id, $entity, $lockMode); } + /** + * @param array $association + * @param array $ownerId + * + * @return CollectionCacheKey + */ + protected function buildCollectionCacheKey(array $association, $ownerId) + { + /** @var ClassMetadata $metadata */ + $metadata = $this->metadataFactory->getMetadataFor($association['sourceEntity']); + + return new CollectionCacheKey($metadata->rootEntityName, $association['fieldName'], $ownerId); + } }