1
0
mirror of synced 2025-01-30 03:51:43 +03:00

DDC-952 - Refactor eager loading entities, it is only allowed for non composite primary key entities.

This commit is contained in:
Benjamin Eberlei 2010-12-31 13:11:01 +01:00
parent 32df9451fd
commit 3d37e436dd
2 changed files with 26 additions and 5 deletions

View File

@ -837,7 +837,6 @@ class BasicEntityPersister
{
$criteria = array();
$sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']);
$joinTableConditions = array();
if ($assoc['isOwningSide']) {
foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) {
if ($sourceClass->containsForeignIdentifier) {

View File

@ -218,6 +218,20 @@ class UnitOfWork implements PropertyChangedListener
//private $_readOnlyObjects = array();
/**
* Map of Entity Class-Names and corresponding IDs that should eager loaded when requested.
*
* @var array
*/
private $eagerLoadingEntities = array();
/**
* Map of Collections that should be eager loaded when requested.
*
* @var array
*/
private $eagerLoadingCollections = array();
/**
* Initializes a new UnitOfWork instance, bound to the given EntityManager.
*
@ -1928,9 +1942,16 @@ class UnitOfWork implements PropertyChangedListener
$newValue = $this->getEntityPersister($assoc['targetEntity'])
->loadOneToOneEntity($assoc, $entity, null, $associatedId);
} else {
if ($assoc['fetch'] == ClassMetadata::FETCH_EAGER && isset($hints['deferEagerLoad'])) {
if (!isset($this->eagerLoadingEntities[$assoc['targetEntity']])) {
$this->eagerLoadingEntities[$assoc['targetEntity']] = array();
// Deferred eager load only works for single identifier classes
if ($assoc['fetch'] == ClassMetadata::FETCH_EAGER) {
if (isset($hints['deferEagerLoad']) && !$targetClass->isIdentifierComposite) {
// TODO: Is there a faster approach?
$this->eagerLoadingEntities[$assoc['targetEntity']][] = current($id);
$newValue = $this->em->getProxyFactory()->getProxy($assoc['targetEntity'], $associatedId);
} else {
// TODO: This is very imperformant, ignore it?
$newValue = $this->em->find($assoc['targetEntity'], $associatedId);
}
// TODO: Is there a faster approach?
@ -2005,7 +2026,8 @@ class UnitOfWork implements PropertyChangedListener
$this->eagerLoadingEntities = array();
foreach ($eagerLoadingEntities AS $entityName => $ids) {
$this->getEntityPersister($entityName)->loadAll($ids);
$class = $this->em->getClassMetadata($entityName);
$this->getEntityPersister($entityName)->loadAll(array_combine($class->identifier, array($ids)));
}
}