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:
commit
3aba23ea35
@ -255,7 +255,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
* 4) All collection updates
|
* 4) All collection updates
|
||||||
* 5) All entity deletions
|
* 5) All entity deletions
|
||||||
*
|
*
|
||||||
* @param object $entity
|
* @param null|object|array $entity
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function commit($entity = null)
|
public function commit($entity = null)
|
||||||
@ -268,8 +268,12 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
// Compute changes done since last commit.
|
// Compute changes done since last commit.
|
||||||
if ($entity === null) {
|
if ($entity === null) {
|
||||||
$this->computeChangeSets();
|
$this->computeChangeSets();
|
||||||
} else {
|
} elseif (is_object($entity)) {
|
||||||
$this->computeSingleEntityChangeSet($entity);
|
$this->computeSingleEntityChangeSet($entity);
|
||||||
|
} elseif (is_array($entity)) {
|
||||||
|
foreach ($entity as $object) {
|
||||||
|
$this->computeSingleEntityChangeSet($object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! ($this->entityInsertions ||
|
if ( ! ($this->entityInsertions ||
|
||||||
|
@ -1056,6 +1056,37 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($address));
|
$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
|
* @group DDC-720
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user