1
0
mirror of synced 2025-02-20 22:23:14 +03:00

Merge branch 'merge_non_mapped_properties'

This commit is contained in:
Alexander 2012-03-12 23:19:16 +01:00
commit 73db4e19d2
4 changed files with 37 additions and 1 deletions

3
UPGRADE_TO_2_3 Normal file
View 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.

View File

@ -1733,7 +1733,9 @@ class UnitOfWork implements PropertyChangedListener
}
// 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 ( ! $class->isIdentifier($name)) {
$prop->setValue($managedCopy, $prop->getValue($entity));

View File

@ -56,6 +56,10 @@ class CmsUser
*/
public $groups;
public $nonPersistedProperty;
public $nonPersistedPropertyObject;
public function __construct() {
$this->phonenumbers = new ArrayCollection;
$this->articles = new ArrayCollection;

View File

@ -905,6 +905,33 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$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()
{
$user = new CmsUser();