[2.0][DDC-237][DDC-216] Fixed. If you're using manual proxy generation through the CLI, please regenerate your proxies.
This commit is contained in:
parent
0a7727e16a
commit
38bf6c665a
@ -572,6 +572,15 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
|
||||
return $this->_coll->partition($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$this->_initialize();
|
||||
return $this->_coll->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -637,11 +646,6 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
|
||||
return $this->remove($offset);
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->_coll->toArray();
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->_coll->key();
|
||||
|
@ -27,7 +27,4 @@ namespace Doctrine\ORM\Proxy;
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
*/
|
||||
interface Proxy
|
||||
{
|
||||
function __isInitialized__();
|
||||
}
|
||||
interface Proxy {}
|
@ -253,26 +253,25 @@ namespace <namespace> {
|
||||
class <proxyClassName> extends \<className> implements \Doctrine\ORM\Proxy\Proxy {
|
||||
private $_entityPersister;
|
||||
private $_identifier;
|
||||
private $_loaded = false;
|
||||
public $__isInitialized__ = false;
|
||||
public function __construct($entityPersister, $identifier) {
|
||||
$this->_entityPersister = $entityPersister;
|
||||
$this->_identifier = $identifier;
|
||||
<constructorInvocation>
|
||||
}
|
||||
private function _load() {
|
||||
if ( ! $this->_loaded) {
|
||||
$this->_loaded = true;
|
||||
if (!$this->__isInitialized__) {
|
||||
$this->__isInitialized__ = true;
|
||||
$this->_entityPersister->load($this->_identifier, $this);
|
||||
unset($this->_entityPersister);
|
||||
unset($this->_identifier);
|
||||
}
|
||||
}
|
||||
public function __isInitialized__() { return $this->_loaded; }
|
||||
|
||||
<methods>
|
||||
|
||||
public function __sleep() {
|
||||
if (!$this->_loaded) {
|
||||
if (!$this->__isInitialized__) {
|
||||
throw new \RuntimeException("Not fully loaded proxy can not be serialized.");
|
||||
}
|
||||
<sleepImpl>
|
||||
|
@ -38,8 +38,7 @@ use Doctrine\Common\Collections\ArrayCollection,
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @internal This class contains performance-critical code. Work with care and
|
||||
* regularly run the ORM performance tests.
|
||||
* @internal This class contains performance-critical code.
|
||||
*/
|
||||
class UnitOfWork implements PropertyChangedListener
|
||||
{
|
||||
@ -401,7 +400,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
foreach ($entitiesToProcess as $entity) {
|
||||
// Ignore uninitialized proxy objects
|
||||
if (/* $entity is readOnly || */ $entity instanceof Proxy && ! $entity->__isInitialized__()) {
|
||||
if (/* $entity is readOnly || */ $entity instanceof Proxy && ! $entity->__isInitialized__) {
|
||||
continue;
|
||||
}
|
||||
// Only MANAGED entities that are NOT SCHEDULED FOR INSERTION are processed here.
|
||||
@ -560,7 +559,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
// Look through the entities, and in any of their associations, for transient
|
||||
// enities, recursively. ("Persistence by reachability")
|
||||
if ($assoc->isOneToOne()) {
|
||||
if ($value instanceof Proxy && ! $value->__isInitialized__()) {
|
||||
if ($value instanceof Proxy && ! $value->__isInitialized__) {
|
||||
return; // Ignore uninitialized proxy objects
|
||||
}
|
||||
$value = array($value);
|
||||
@ -1732,7 +1731,12 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if (isset($this->_identityMap[$class->rootEntityName][$idHash])) {
|
||||
$entity = $this->_identityMap[$class->rootEntityName][$idHash];
|
||||
$oid = spl_object_hash($entity);
|
||||
if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
|
||||
$entity->__isInitialized__ = true;
|
||||
$overrideLocalValues = true;
|
||||
} else {
|
||||
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
|
||||
}
|
||||
} else {
|
||||
//$entity = clone $class->prototype;
|
||||
$entity = new $className;
|
||||
|
@ -34,7 +34,7 @@ class DefaultValuesTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$user2 = $this->_em->getReference(get_class($user), $userId);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->assertFalse($user2->__isInitialized__());
|
||||
$this->assertFalse($user2->__isInitialized__);
|
||||
|
||||
$a = new DefaultValueAddress;
|
||||
$a->country = 'de';
|
||||
@ -46,7 +46,7 @@ class DefaultValuesTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->persist($a);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertFalse($user2->__isInitialized__());
|
||||
$this->assertFalse($user2->__isInitialized__);
|
||||
$this->_em->clear();
|
||||
|
||||
$a2 = $this->_em->find(get_class($a), $a->id);
|
||||
|
112
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php
Normal file
112
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityX'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityY'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityZ')
|
||||
));
|
||||
}
|
||||
|
||||
public function testUninitializedProxyIsInitializedOnFetchJoin()
|
||||
{
|
||||
$x = new DDC237EntityX;
|
||||
$y = new DDC237EntityY;
|
||||
$z = new DDC237EntityZ;
|
||||
|
||||
$x->data = 'X';
|
||||
$y->data = 'Y';
|
||||
$z->data = 'Z';
|
||||
|
||||
$x->y = $y;
|
||||
$z->y = $y;
|
||||
|
||||
$this->_em->persist($x);
|
||||
$this->_em->persist($y);
|
||||
$this->_em->persist($z);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$x2 = $this->_em->find(get_class($x), $x->id); // proxy injected for Y
|
||||
$this->assertTrue($x2->y instanceof \Doctrine\ORM\Proxy\Proxy);
|
||||
$this->assertFalse($x2->y->__isInitialized__);
|
||||
|
||||
// proxy for Y is in identity map
|
||||
|
||||
$z2 = $this->_em->createQuery('select z,y from ' . get_class($z) . ' z join z.y y where z.id = ?1')
|
||||
->setParameter(1, $z->id)
|
||||
->getSingleResult();
|
||||
$this->assertTrue($z2->y instanceof \Doctrine\ORM\Proxy\Proxy);
|
||||
$this->assertTrue($z2->y->__isInitialized__);
|
||||
$this->assertEquals('Y', $z2->y->data);
|
||||
$this->assertEquals($y->id, $z2->y->id);
|
||||
|
||||
// since the Y is the same, the instance from the identity map is
|
||||
// used, even if it is a proxy.
|
||||
|
||||
$this->assertNotSame($x, $x2);
|
||||
$this->assertNotSame($z, $z2);
|
||||
$this->assertSame($z2->y, $x2->y);
|
||||
$this->assertTrue($z2->y instanceof \Doctrine\ORM\Proxy\Proxy);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Entity @Table(name="ddc237_x")
|
||||
*/
|
||||
class DDC237EntityX
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="integer") @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @Column(type="string")
|
||||
*/
|
||||
public $data;
|
||||
/**
|
||||
* @OneToOne(targetEntity="DDC237EntityY")
|
||||
* @JoinColumn(name="y_id", referencedColumnName="id")
|
||||
*/
|
||||
public $y;
|
||||
}
|
||||
|
||||
|
||||
/** @Entity @Table(name="ddc237_y") */
|
||||
class DDC237EntityY
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="integer") @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @Column(type="string")
|
||||
*/
|
||||
public $data;
|
||||
}
|
||||
|
||||
/** @Entity @Table(name="ddc237_z") */
|
||||
class DDC237EntityZ
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
|
||||
public $id;
|
||||
/** @Column(type="string") */
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="DDC237EntityY")
|
||||
* @JoinColumn(name="y_id", referencedColumnName="id")
|
||||
*/
|
||||
public $y;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user