From b456cffa2d2340fb078ba7aebba92985578db333 Mon Sep 17 00:00:00 2001 From: Darien Hager Date: Wed, 30 Sep 2015 21:04:22 -0700 Subject: [PATCH] Move final cascade-persist-checking so that it covers not just normal flushes, but also flushes where specific entities are singled out. --- lib/Doctrine/ORM/UnitOfWork.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7d4d8d80a..b3f3fb23d 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -347,6 +347,8 @@ class UnitOfWork implements PropertyChangedListener } } + $this->assertNoCascadingGaps(); + if ( ! ($this->entityInsertions || $this->entityDeletions || $this->entityUpdates || @@ -829,16 +831,6 @@ class UnitOfWork implements PropertyChangedListener } } } - - /** - * Filter out any entities that we (successfully) managed to schedule - * for insertion. - */ - $entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions); - if(count($entitiesNeedingCascadePersist) > 0){ - list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0]; - throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); - } } /** @@ -3395,6 +3387,26 @@ class UnitOfWork implements PropertyChangedListener return $id1 === $id2 || implode(' ', $id1) === implode(' ', $id2); } + /** + * Checks that there are no new entities found through non-cascade-persist + * paths which are not also scheduled for insertion through valid paths. + * + * @return void + * @throws ORMInvalidArgumentException + */ + private function assertNoCascadingGaps() + { + /** + * Filter out any entities that we (successfully) managed to schedule + * for insertion. + */ + $entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions); + if(count($entitiesNeedingCascadePersist) > 0){ + list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0]; + throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); + } + } + /** * @param object $entity * @param object $managedCopy