1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Merge pull request #304 from doctrine/feature/flush-many-documents

Allow flushing of many entities by passing an array of entities.
This commit is contained in:
Benjamin Eberlei 2012-03-22 12:34:01 -07:00
commit 3aba23ea35
2 changed files with 37 additions and 2 deletions

View File

@ -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 ||

View File

@ -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
*/