From f731a083b61e5d2f0b46e7800fa465feca72a1ab Mon Sep 17 00:00:00 2001 From: romanb Date: Mon, 12 Oct 2009 11:55:22 +0000 Subject: [PATCH] [2.0][DDC-41] Fixed. Also related to DDC-2. --- lib/Doctrine/ORM/Proxy/Proxy.php | 11 +++++++++++ lib/Doctrine/ORM/Proxy/ProxyClassGenerator.php | 4 ++-- lib/Doctrine/ORM/UnitOfWork.php | 12 +++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 lib/Doctrine/ORM/Proxy/Proxy.php diff --git a/lib/Doctrine/ORM/Proxy/Proxy.php b/lib/Doctrine/ORM/Proxy/Proxy.php new file mode 100644 index 000000000..751b9a862 --- /dev/null +++ b/lib/Doctrine/ORM/Proxy/Proxy.php @@ -0,0 +1,11 @@ + + * @since 2.0 + */ +interface Proxy {} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Proxy/ProxyClassGenerator.php b/lib/Doctrine/ORM/Proxy/ProxyClassGenerator.php index 36b7d5e76..80b344694 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyClassGenerator.php +++ b/lib/Doctrine/ORM/Proxy/ProxyClassGenerator.php @@ -214,7 +214,7 @@ class ProxyClassGenerator ' extends \ { + class extends \ implements \Doctrine\ORM\Proxy\Proxy { private $_entityPersister; private $_identifier; private $_loaded = false; @@ -247,7 +247,7 @@ namespace Doctrine\Generated\Proxies { ' extends \ { + class extends \ implements \Doctrine\ORM\Proxy\Proxy { private $_em; private $_assoc; private $_owner; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 803ac488d..97a53b802 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -26,7 +26,8 @@ use Doctrine\Common\Collections\ArrayCollection, Doctrine\Common\DoctrineException, Doctrine\Common\NotifyPropertyChanged, Doctrine\Common\PropertyChangedListener, - Doctrine\ORM\Event\LifecycleEventArgs; + Doctrine\ORM\Event\LifecycleEventArgs, + Doctrine\ORM\Proxy\Proxy; /** * The UnitOfWork is responsible for tracking changes to objects during an @@ -554,10 +555,13 @@ class UnitOfWork implements PropertyChangedListener if ( ! $assoc->isCascadePersist) { return; // "Persistence by reachability" only if persist cascade specified } - + // Look through the entities, and in any of their associations, for transient // enities, recursively. ("Persistence by reachability") if ($assoc->isOneToOne()) { + if ($value instanceof Proxy) { + return; // Ignore proxy objects + } $value = array($value); } $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName); @@ -586,7 +590,9 @@ class UnitOfWork implements PropertyChangedListener $data[$name] = $refProp->getValue($entry); $changeSet[$name] = array(null, $data[$name]); if (isset($targetClass->associationMappings[$name])) { - $this->_computeAssociationChanges($targetClass->associationMappings[$name], $data[$name]); + if ($data[$name] !== null) { + $this->_computeAssociationChanges($targetClass->associationMappings[$name], $data[$name]); + } } }