diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 9848499d9..c07afc173 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2659,7 +2659,10 @@ class UnitOfWork implements PropertyChangedListener $this->entityIdentifiers[$newValueOid] = $associatedId; $this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue; - if ($newValue instanceof NotifyPropertyChanged) { + if ( + $newValue instanceof NotifyPropertyChanged && + ( ! $newValue instanceof Proxy || $newValue->__isInitialized()) + ) { $newValue->addPropertyChangedListener($this); } $this->entityStates[$newValueOid] = self::STATE_MANAGED; @@ -3003,7 +3006,7 @@ class UnitOfWork implements PropertyChangedListener $this->addToIdentityMap($entity); - if ($entity instanceof NotifyPropertyChanged) { + if ($entity instanceof NotifyPropertyChanged && ( ! $entity instanceof Proxy || $entity->__isInitialized())) { $entity->addPropertyChangedListener($this); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php index ab5d2934a..fd2288eed 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php @@ -50,7 +50,14 @@ class DDC1690Test extends \Doctrine\Tests\OrmFunctionalTestCase $child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId); $this->assertEquals(1, count($parent->listeners)); - $this->assertEquals(1, count($child->listeners)); + $this->assertInstanceOf( + 'Doctrine\\ORM\\Proxy\\Proxy', + $child, + 'Verifying that $child is a proxy before using proxy API' + ); + $this->assertCount(0, $child->listeners); + $child->__load(); + $this->assertCount(1, $child->listeners); unset($parent, $child); $parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);