Merge branch 'merge_non_mapped_properties'
This commit is contained in:
commit
73db4e19d2
3
UPGRADE_TO_2_3
Normal file
3
UPGRADE_TO_2_3
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Merge copies non persisted properties too
|
||||||
|
|
||||||
|
When merging an entity in UoW not only mapped properties are copied, but also others.
|
@ -1733,7 +1733,9 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge state of $entity into existing (managed) entity
|
// Merge state of $entity into existing (managed) entity
|
||||||
foreach ($class->reflFields as $name => $prop) {
|
foreach ($class->reflClass->getProperties() as $prop) {
|
||||||
|
$name = $prop->name;
|
||||||
|
$prop->setAccessible(true);
|
||||||
if ( ! isset($class->associationMappings[$name])) {
|
if ( ! isset($class->associationMappings[$name])) {
|
||||||
if ( ! $class->isIdentifier($name)) {
|
if ( ! $class->isIdentifier($name)) {
|
||||||
$prop->setValue($managedCopy, $prop->getValue($entity));
|
$prop->setValue($managedCopy, $prop->getValue($entity));
|
||||||
|
@ -56,6 +56,10 @@ class CmsUser
|
|||||||
*/
|
*/
|
||||||
public $groups;
|
public $groups;
|
||||||
|
|
||||||
|
public $nonPersistedProperty;
|
||||||
|
|
||||||
|
public $nonPersistedPropertyObject;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->phonenumbers = new ArrayCollection;
|
$this->phonenumbers = new ArrayCollection;
|
||||||
$this->articles = new ArrayCollection;
|
$this->articles = new ArrayCollection;
|
||||||
|
@ -905,6 +905,33 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user2);
|
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMergeNonPersistedProperties()
|
||||||
|
{
|
||||||
|
$user = new CmsUser();
|
||||||
|
$user->username = "beberlei";
|
||||||
|
$user->name = "Benjamin E.";
|
||||||
|
$user->status = 'active';
|
||||||
|
$user->nonPersistedProperty = 'test';
|
||||||
|
$user->nonPersistedPropertyObject = new CmsPhonenumber();
|
||||||
|
|
||||||
|
$managedUser = $this->_em->merge($user);
|
||||||
|
$this->assertEquals('test', $managedUser->nonPersistedProperty);
|
||||||
|
$this->assertSame($user->nonPersistedProperty, $managedUser->nonPersistedProperty);
|
||||||
|
$this->assertSame($user->nonPersistedPropertyObject, $managedUser->nonPersistedPropertyObject);
|
||||||
|
|
||||||
|
$this->assertTrue($user !== $managedUser);
|
||||||
|
$this->assertTrue($this->_em->contains($managedUser));
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
$userId = $managedUser->id;
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$user2 = $this->_em->find(get_class($managedUser), $userId);
|
||||||
|
$this->assertNull($user2->nonPersistedProperty);
|
||||||
|
$this->assertNull($user2->nonPersistedPropertyObject);
|
||||||
|
$this->assertEquals('active', $user2->status);
|
||||||
|
}
|
||||||
|
|
||||||
public function testMergeThrowsExceptionIfEntityWithGeneratedIdentifierDoesNotExist()
|
public function testMergeThrowsExceptionIfEntityWithGeneratedIdentifierDoesNotExist()
|
||||||
{
|
{
|
||||||
$user = new CmsUser();
|
$user = new CmsUser();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user