From 1672448993b0c72d842738507055ec535b179ddc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 23 Jan 2015 16:01:48 +0100 Subject: [PATCH] #1277 DDC-3346 DDC-3531 - renaming persister context switch for clarity --- .../Entity/BasicEntityPersister.php | 24 ++++++++++++------- .../Entity/JoinedSubclassPersister.php | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index b91f850b9..a1ad364e0 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -691,7 +691,7 @@ class BasicEntityPersister implements EntityPersister */ public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = null, $limit = null, array $orderBy = null) { - $this->loadPersisterContext(null, $limit); + $this->switchPersisterContext(null, $limit); $sql = $this->getSelectSQL($criteria, $assoc, $lockMode, $limit, null, $orderBy); list($params, $types) = $this->expandParameters($criteria); @@ -863,7 +863,7 @@ class BasicEntityPersister implements EntityPersister */ public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null) { - $this->loadPersisterContext($offset, $limit); + $this->switchPersisterContext($offset, $limit); $sql = $this->getSelectSQL($criteria, null, null, $limit, $offset, $orderBy); list($params, $types) = $this->expandParameters($criteria); @@ -879,7 +879,7 @@ class BasicEntityPersister implements EntityPersister */ public function getManyToManyCollection(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $this->loadPersisterContext($offset, $limit); + $this->switchPersisterContext($offset, $limit); $stmt = $this->getManyToManyStatement($assoc, $sourceEntity, $offset, $limit); @@ -954,7 +954,7 @@ class BasicEntityPersister implements EntityPersister */ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $this->loadPersisterContext($offset, $limit); + $this->switchPersisterContext($offset, $limit); $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); $class = $sourceClass; @@ -1021,7 +1021,7 @@ class BasicEntityPersister implements EntityPersister */ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = null) { - $this->loadPersisterContext($offset, $limit); + $this->switchPersisterContext($offset, $limit); $lockSql = ''; $joinSql = ''; @@ -1686,7 +1686,7 @@ class BasicEntityPersister implements EntityPersister */ public function getOneToManyCollection(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $this->loadPersisterContext($offset, $limit); + $this->switchPersisterContext($offset, $limit); $stmt = $this->getOneToManyStatement($assoc, $sourceEntity, $offset, $limit); @@ -1715,7 +1715,7 @@ class BasicEntityPersister implements EntityPersister */ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $this->loadPersisterContext($offset, $limit); + $this->switchPersisterContext($offset, $limit); $criteria = array(); $parameters = array(); @@ -1955,7 +1955,15 @@ class BasicEntityPersister implements EntityPersister return $sql ? "(" . $sql . ")" : ""; // Wrap again to avoid "X or Y and FilterConditionSQL" } - protected function loadPersisterContext($offset, $limit) + /** + * Switches persister context according to current query offset/limits + * + * This is due to the fact that to-many associations cannot be fetch-joined when a limit is involved + * + * @param null|int $offset + * @param null|int $limit + */ + protected function switchPersisterContext($offset, $limit) { if (null === $offset && null === $limit) { $this->currentPersisterContext = $this->cachedPersisterContexts['noLimits']; diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 6f33baf9c..5d259e4af 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -299,7 +299,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister */ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = null) { - $this->loadPersisterContext($offset, $limit); + $this->switchPersisterContext($offset, $limit); $baseTableAlias = $this->getSQLTableAlias($this->class->name); $joinSql = $this->getJoinSql($baseTableAlias);