Skip to content

Commit

Permalink
Allow flushing of many entities by passing an array of entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Mar 15, 2012
1 parent 44d7d23 commit 24e8088
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ||
Expand Down
31 changes: 31 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 24e8088

Please sign in to comment.