1
0
mirror of synced 2025-02-20 14:13:15 +03:00

make merge copy non persited properties too

This commit is contained in:
Klein Florian 2011-11-02 12:34:28 +01:00 committed by Alexander
parent 775936399e
commit ac1ffaf7e9
3 changed files with 34 additions and 1 deletions

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();