diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index cc1431949..bcabaa7d3 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -40,14 +40,14 @@ class CommitOrderCalculator private $_sorted = array(); /** - * Clears the current graph and the last result. + * Clears the current graph. * * @return void */ public function clear() { - $this->_nodes = array(); - $this->_sorted = array(); + $this->_classes = + $this->_relatedClasses = array(); } /** @@ -65,12 +65,10 @@ class CommitOrderCalculator if ($nodeCount == 0) { return array(); } else if ($nodeCount == 1) { - return array(0 => array_pop($this->_classes)); + return array_values($this->_classes); } // Init - $this->_sorted = array(); - $this->_nodeStates = array(); foreach ($this->_classes as $node) { $this->_nodeStates[$node->name] = self::NOT_VISITED; } @@ -82,7 +80,12 @@ class CommitOrderCalculator } } - return array_reverse($this->_sorted); + $sorted = array_reverse($this->_sorted); + + $this->_sorted = + $this->_nodeStates = array(); + + return $sorted; } private function _visitNode($node) @@ -94,10 +97,6 @@ class CommitOrderCalculator if ($this->_nodeStates[$relatedNode->name] == self::NOT_VISITED) { $this->_visitNode($relatedNode); } - if ($this->_nodeStates[$relatedNode->name] == self::IN_PROGRESS) { - // back edge => cycle - //TODO: anything to do here? - } } } diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index e44721c51..74e52c5df 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -51,15 +51,6 @@ abstract class AssociationMapping */ const FETCH_EAGER = 3; - /** - * Cascade types enumeration. - * - * @var array - */ - protected static $_cascadeTypes = array( - 'all', 'none', 'save', 'delete', 'refresh', 'merge' - ); - public $cascades = array(); public $isCascadeRemove; public $isCascadePersist; diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 692a223ac..2a3cb4eda 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -214,7 +214,7 @@ class JoinedSubclassPersister extends StandardEntityPersister $this->_prepareData($entity, $updateData); $id = array_combine( - $this->_class->getIdentifierFieldNames(), + $this->_class->getIdentifierColumnNames(), $this->_em->getUnitOfWork()->getEntityIdentifier($entity) ); diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index c07663022..db67ef80e 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -205,7 +205,7 @@ class StandardEntityPersister $updateData = array(); $this->_prepareData($entity, $updateData); $id = array_combine( - $this->_class->identifier, + $this->_class->getIdentifierColumnNames(), $this->_em->getUnitOfWork()->getEntityIdentifier($entity) ); $tableName = $this->_class->primaryTable['name']; @@ -251,8 +251,7 @@ class StandardEntityPersister $sql = 'UPDATE ' . $tableName . ' SET ' . implode(', ', $set) - . ' WHERE ' . implode(' = ? AND ', array_keys($where)) - . ' = ?'; + . ' WHERE ' . implode(' = ? AND ', array_keys($where)) . ' = ?'; $result = $this->_conn->executeUpdate($sql, $params); @@ -352,7 +351,7 @@ class StandardEntityPersister } // Special case: One-one self-referencing of the same class. - if ($newVal !== null && $assocMapping->sourceEntityName == $assocMapping->targetEntityName) { + if ($newVal !== null /*&& $assocMapping->sourceEntityName == $assocMapping->targetEntityName*/) { $oid = spl_object_hash($newVal); $isScheduledForInsert = $uow->isScheduledForInsert($newVal); if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) { @@ -363,12 +362,6 @@ class StandardEntityPersister $field => array(null, $newVal) )); $newVal = null; - } else if ($isInsert && ! $isScheduledForInsert && $uow->getEntityState($newVal) == UnitOfWork::STATE_MANAGED) { - // $newVal is already fully persisted. - // Schedule an extra update for it, so that the foreign key(s) are properly set. - $uow->scheduleExtraUpdate($newVal, array( - $field => array(null, $entity) - )); } } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 4831b7efc..1a23e495f 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -265,15 +265,15 @@ class UnitOfWork implements PropertyChangedListener $this->_orphanRemovals)) { return; // Nothing to do. } - - // Now we need a commit order to maintain referential integrity - $commitOrder = $this->_getCommitOrder(); if ($this->_orphanRemovals) { foreach ($this->_orphanRemovals as $orphan) { $this->remove($orphan); } } + + // Now we need a commit order to maintain referential integrity + $commitOrder = $this->_getCommitOrder(); $conn = $this->_em->getConnection(); @@ -681,7 +681,7 @@ class UnitOfWork implements PropertyChangedListener } foreach ($this->_entityInsertions as $oid => $entity) { - if (get_class($entity) == $className) { + if (get_class($entity) === $className) { $persister->addInsert($entity); unset($this->_entityInsertions[$oid]); if ($hasLifecycleCallbacks || $hasListeners) { @@ -802,15 +802,14 @@ class UnitOfWork implements PropertyChangedListener $this->_entityDeletions ); } - - // TODO: We can cache computed commit orders in the metadata cache! - // Check cache at this point here! - + // See if there are any new classes in the changeset, that are not in the // commit order graph yet (dont have a node). $newNodes = array(); - foreach ($entityChangeSet as $entity) { + $classesInChangeSet = array(); + foreach ($entityChangeSet as $oid => $entity) { $className = get_class($entity); + $classesInChangeSet[$className] = true; if ( ! $this->_commitOrderCalculator->hasClass($className)) { $class = $this->_em->getClassMetadata($className); $this->_commitOrderCalculator->addClass($class); @@ -820,14 +819,12 @@ class UnitOfWork implements PropertyChangedListener // Calculate dependencies for new nodes foreach ($newNodes as $class) { - foreach ($class->associationMappings as $assocMapping) { - //TODO: should skip target classes that are not in the changeset. - if ($assocMapping->isOwningSide) { - $targetClass = $this->_em->getClassMetadata($assocMapping->targetEntityName); + foreach ($class->associationMappings as $assoc) { + if ($assoc->isOwningSide && $assoc->isOneToOne() && isset($classesInChangeSet[$assoc->targetEntityName])) { + $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName); if ( ! $this->_commitOrderCalculator->hasClass($targetClass->name)) { $this->_commitOrderCalculator->addClass($targetClass); } - // add dependency ($targetClass before $class) $this->_commitOrderCalculator->addDependency($targetClass, $class); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index d45600605..4e36f4920 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -44,7 +44,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); - $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.id asc"); + $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.name desc"); $entities = $query->getResult();