Don't load uninitialized proxies after merging.
Previous patch avoided initialization of proxies before merging, mainly to fix a bug with merging. However, later on, doctrine tries again to load the proxy. This is unnecessary and thus has been removed. This way, a round trip to the database is saved.
This commit is contained in:
parent
ec35d4886c
commit
318b23097b
@ -1848,10 +1848,6 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$class->setIdentifierValues($managedCopy, $id);
|
||||
|
||||
$this->persistNew($class, $managedCopy);
|
||||
} else {
|
||||
if ($managedCopy instanceof Proxy && ! $managedCopy->__isInitialized__) {
|
||||
$managedCopy->__load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
|
||||
use Doctrine\ORM\Proxy\Proxy;
|
||||
use Doctrine\ORM\Tools\ToolsException;
|
||||
|
||||
class MergeUninitializedProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase {
|
||||
@ -43,6 +44,7 @@ class MergeUninitializedProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$file = $em->find(__NAMESPACE__ . '\MUPFile', $fileId);
|
||||
$picture = unserialize($serializedPicture);
|
||||
|
||||
$picture = $em->merge($picture);
|
||||
|
||||
$this->assertEquals($file, $picture->file, "Unserialized proxy was not merged into managed entity");
|
||||
@ -68,6 +70,7 @@ class MergeUninitializedProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$em->clear();
|
||||
|
||||
$file = $em->find(__NAMESPACE__ . '\MUPFile', $fileId);
|
||||
|
||||
$picture = $em->merge($picture);
|
||||
|
||||
$this->assertEquals($file, $picture->file, "Detached proxy was not merged into managed entity");
|
||||
@ -98,9 +101,17 @@ class MergeUninitializedProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$em->clear();
|
||||
|
||||
$picture2 = $em->find(__NAMESPACE__ . '\MUPPicture', $picture2Id);
|
||||
$this->assertFalse($picture->file->__isInitialized());
|
||||
$picture = unserialize($serializedPicture);
|
||||
|
||||
$this->assertTrue($picture->file instanceof Proxy);
|
||||
$this->assertFalse($picture->file->__isInitialized());
|
||||
|
||||
$picture = $em->merge($picture);
|
||||
|
||||
$this->assertTrue($picture->file instanceof Proxy);
|
||||
$this->assertFalse($picture->file->__isInitialized(), 'Proxy has been initialized during merge.');
|
||||
|
||||
$this->assertEquals($picture2->file, $picture->file, "Unserialized proxy was not merged into managed proxy");
|
||||
}
|
||||
|
||||
@ -128,8 +139,15 @@ class MergeUninitializedProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$em->clear();
|
||||
|
||||
$picture2 = $em->find(__NAMESPACE__ . '\MUPPicture', $picture2Id);
|
||||
|
||||
$this->assertTrue($picture->file instanceof Proxy);
|
||||
$this->assertFalse($picture->file->__isInitialized());
|
||||
|
||||
$picture = $em->merge($picture);
|
||||
|
||||
$this->assertTrue($picture->file instanceof Proxy);
|
||||
$this->assertFalse($picture->file->__isInitialized(), 'Proxy has been initialized during merge.');
|
||||
|
||||
$this->assertEquals($picture2->file, $picture->file, "Detached proxy was not merged into managed proxy");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user