Permalink
Browse files

Added constant

  • Loading branch information...
1 parent 057e86e commit e561f47cb2205565eb873f0643637477bfcfc2ff @stefankleff committed Apr 8, 2013
@@ -19,6 +19,7 @@
namespace Doctrine\ORM\Internal\Hydration;
+use Doctrine\ORM\UnitOfWork;
use PDO;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\PersistentCollection;
@@ -94,8 +95,8 @@ protected function prepare()
$this->resultCounter = 0;
- if ( ! isset($this->_hints['deferEagerLoad'])) {
- $this->_hints['deferEagerLoad'] = true;
+ if ( ! isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD])) {
+ $this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] = true;
}
foreach ($this->_rsm->aliasMap as $dqlAlias => $className) {
@@ -152,7 +153,7 @@ protected function prepare()
*/
protected function cleanup()
{
- $eagerLoad = (isset($this->_hints['deferEagerLoad'])) && $this->_hints['deferEagerLoad'] == true;
+ $eagerLoad = (isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD])) && $this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] == true;
parent::cleanup();
@@ -851,7 +851,7 @@ public function loadCriteria(Criteria $criteria)
$stmt = $this->conn->executeQuery($query, $params, $types);
$hydrator = $this->em->newHydrator(($this->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
- return $hydrator->hydrateAll($stmt, $this->rsm, array('deferEagerLoad' => true));
+ return $hydrator->hydrateAll($stmt, $this->rsm, array(UnitOfWork::HINT_DEFEREAGERLOAD => true));
}
/**
@@ -908,7 +908,7 @@ public function loadAll(array $criteria = array(), array $orderBy = null, $limit
$hydrator = $this->em->newHydrator(($this->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
- return $hydrator->hydrateAll($stmt, $this->rsm, array('deferEagerLoad' => true));
+ return $hydrator->hydrateAll($stmt, $this->rsm, array(UnitOfWork::HINT_DEFEREAGERLOAD => true));
}
/**
@@ -939,7 +939,7 @@ public function getManyToManyCollection(array $assoc, $sourceEntity, $offset = n
private function loadArrayFromStatement($assoc, $stmt)
{
$rsm = $this->rsm;
- $hints = array('deferEagerLoad' => true);
+ $hints = array(UnitOfWork::HINT_DEFEREAGERLOAD => true);
if (isset($assoc['indexBy'])) {
$rsm = clone ($this->rsm); // this is necessary because the "default rsm" should be changed.
@@ -962,8 +962,8 @@ private function loadCollectionFromStatement($assoc, $stmt, $coll)
{
$rsm = $this->rsm;
$hints = array(
- 'deferEagerLoad' => true,
- 'collection' => $coll
+ UnitOfWork::HINT_DEFEREAGERLOAD => true,
+ 'collection' => $coll
);
if (isset($assoc['indexBy'])) {
@@ -77,6 +77,13 @@ class UnitOfWork implements PropertyChangedListener
const STATE_REMOVED = 4;
/**
+ * Hint used to collect all primary keys of associated entities during hydration
+ * and execute it in a dedicated query afterwards
+ * @see https://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html?highlight=eager#temporarily-change-fetch-mode-in-dql
+ */
+ const HINT_DEFEREAGERLOAD = 'deferEagerLoad';
+
+ /**
* The identity map that holds references to all managed entities that have
* an identity. The entities are grouped by their class name.
* Since all classes in a hierarchy must share the same identifier set,
@@ -2616,7 +2623,7 @@ public function createEntity($className, array $data, &$hints = array())
// this association is marked as eager fetch, and its an uninitialized proxy (wtf!)
// then we can append this entity for eager loading!
if ($hints['fetchMode'][$class->name][$field] == ClassMetadata::FETCH_EAGER &&
- isset($hints['deferEagerLoad']) &&
+ isset($hints[self::HINT_DEFEREAGERLOAD]) &&
!$targetClass->isIdentifierComposite &&
$newValue instanceof Proxy &&
$newValue->__isInitialized__ === false) {
@@ -2641,7 +2648,7 @@ public function createEntity($className, array $data, &$hints = array())
break;
// Deferred eager load only works for single identifier classes
- case (isset($hints['deferEagerLoad']) && ! $targetClass->isIdentifierComposite):
+ case (isset($hints[self::HINT_DEFEREAGERLOAD]) && ! $targetClass->isIdentifierComposite):
// TODO: Is there a faster approach?
$this->eagerLoadingEntities[$targetClass->rootEntityName][$relatedIdHash] = current($associatedId);

0 comments on commit e561f47

Please sign in to comment.