Permalink
Browse files

Allow flushing of many entities by passing an array of entities.

  • Loading branch information...
1 parent 44d7d23 commit 24e808844b71e837c6725ebe606e5aa5d9382645 @jwage jwage committed Mar 15, 2012
Showing with 37 additions and 2 deletions.
  1. +6 −2 lib/Doctrine/ORM/UnitOfWork.php
  2. +31 −0 tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
View
8 lib/Doctrine/ORM/UnitOfWork.php
@@ -255,7 +255,7 @@ public function __construct(EntityManager $em)
* 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 @@ public function commit($entity = null)
// 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 ||
View
31 tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
@@ -1056,6 +1056,37 @@ public function testClearWithEntityName()
$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
*/

0 comments on commit 24e8088

Please sign in to comment.