DDC-1414: UnitOfWork#getCommitOrder() does not add dependencies for all related classes #2038

doctrinebot opened this Issue Oct 11, 2011 · 2 comments

2 participants


Jira issue originally created by user pmahanen:

getCommitOrder() does not add dependencies for all related classes. This causes database-level exceptions in certain cases, as insertion order can be calculated incorrectly, and foreign key constraints fail.

An example case in pseudocode:

A: ManyToOne to B, nullable=true
B: ManyToOne to C, nullable=false
C: no owning relations

a = new A()
em->flush()     // does CommitOrderCalculator->addClass(B), but does not add B's dependency to C

c = new C()
b = new B(c)

em->flush()     // CommitOrderCalculator->hasClass(B) == true, dependencies not added, foreign key constraint fails

Suggested fix against master:

diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index ea516f3..991acac 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
<ins></ins><ins> b/lib/Doctrine/ORM/UnitOfWork.php
@@ -853,6 </ins>853,7 @@ class UnitOfWork implements PropertyChangedListener
                     $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
                     if ( ! $calc->hasClass($targetClass->name)) {
+                        $newNodes[] = $targetClass;
                     $calc->addDependency($targetClass, $class);
                     // If the target class has mapped subclasses,

This $newNodes[] push is done for all new classes in $entityChangeSet (above) and $targetClass->subClasses (below), but not for $targetClass itself. I'm assuming this is a bug, not by design.


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1.3 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment