From 5e19e1bed3ee593e38c7a7d882232d43df710d7c Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 4 May 2013 13:36:37 +0200 Subject: [PATCH] [DDC-2267] Allow EntityManager#flush($entity) to be called on entities scheduled for removal. --- lib/Doctrine/ORM/UnitOfWork.php | 8 +++++--- .../Tests/ORM/Functional/BasicFunctionalTest.php | 13 +++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index b45e4921b..68fde5d2c 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -421,13 +421,15 @@ class UnitOfWork implements PropertyChangedListener */ private function computeSingleEntityChangeSet($entity) { - if ( $this->getEntityState($entity) !== self::STATE_MANAGED) { - throw new \InvalidArgumentException("Entity has to be managed for single computation " . self::objToStr($entity)); + $state = $this->getEntityState($entity); + + if ($state !== self::STATE_MANAGED && $state !== self::STATE_REMOVED) { + throw new \InvalidArgumentException("Entity has to be managed or scheduled for removal for single computation " . self::objToStr($entity)); } $class = $this->em->getClassMetadata(get_class($entity)); - if ($class->isChangeTrackingDeferredImplicit()) { + if ($state === self::STATE_MANAGED && $class->isChangeTrackingDeferredImplicit()) { $this->persist($entity); } diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 221bc011f..2fb830a92 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -1118,7 +1118,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->username = 'domnikl'; $user->status = 'developer'; - $this->setExpectedException('InvalidArgumentException', 'Entity has to be managed for single computation'); + $this->setExpectedException('InvalidArgumentException', 'Entity has to be managed or scheduled for removal for single computation'); $this->_em->flush($user); } @@ -1202,8 +1202,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase /** * @group DDC-720 * @group DDC-1612 + * @group DDC-2267 */ - public function testFlushSingleNewEntity() + public function testFlushSingleNewEntityThenRemove() { $user = new CmsUser; $user->name = 'Dominik'; @@ -1212,6 +1213,14 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush($user); + + $userId = $user->id; + + $this->_em->remove($user); + $this->_em->flush($user); + $this->_em->clear(); + + $this->assertNull($this->_em->find(get_class($user), $userId)); } /**