diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index fa0178c34..410f3b2c6 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -255,7 +255,7 @@ class UnitOfWork implements PropertyChangedListener * 4) All collection updates * 5) All entity deletions * - * @param object $entity + * @param null|object|array $entity * @return void */ public function commit($entity = null) @@ -268,8 +268,12 @@ class UnitOfWork implements PropertyChangedListener // Compute changes done since last commit. if ($entity === null) { $this->computeChangeSets(); - } else { + } elseif (is_object($entity)) { $this->computeSingleEntityChangeSet($entity); + } elseif (is_array($entity)) { + foreach ($entity as $object) { + $this->computeSingleEntityChangeSet($object); + } } if ( ! ($this->entityInsertions || diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 75005acb1..415069a35 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -1056,6 +1056,37 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($address)); } + public function testFlushManyExplicitEntities() + { + $userA = new CmsUser; + $userA->username = 'UserA'; + $userA->name = 'UserA'; + + $userB = new CmsUser; + $userB->username = 'UserB'; + $userB->name = 'UserB'; + + $userC = new CmsUser; + $userC->username = 'UserC'; + $userC->name = 'UserC'; + + $this->_em->persist($userA); + $this->_em->persist($userB); + $this->_em->persist($userC); + + $this->_em->flush(array($userA, $userB, $userB)); + + $userC->name = 'changed name'; + + $this->_em->flush(array($userA, $userB)); + $this->_em->refresh($userC); + + $this->assertTrue($userA->id > 0, 'user a has an id'); + $this->assertTrue($userB->id > 0, 'user b has an id'); + $this->assertTrue($userC->id > 0, 'user c has an id'); + $this->assertEquals('UserC', $userC->name, 'name has not changed because we did not flush it'); + } + /** * @group DDC-720 */