DDC-1193: cascadeRemove misses associations due to proxy not being initialized #1798

Closed
doctrinebot opened this Issue Jun 3, 2011 · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user xanf:

Let's assume you have two One-to-One relations A>B>C (all include cascade remove). You are deleting object A, while object B is not initialized (and so it will be a proxy). In that case the object C is not deleted because UOW misses relation B>C since proxy of B is not initialized

@doctrinebot

Comment created by xanf:

Test case. Expected to be put into Tests/ORM/Functional/Ticket folder

@doctrinebot

Comment created by xanf:

Right now i'm using this hack inside of UOW:

diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index 90d3117..a4891c7 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
<ins></ins><ins> b/lib/Doctrine/ORM/UnitOfWork.php
@@ -1702,7 </ins>1702,10 @@ class UnitOfWork implements PropertyChangedListener
             if ( ! $assoc['isCascadeRemove']) {
                 continue;
             }
-            //TODO: If $entity instanceof Proxy => Initialize ?
<ins>            if ($entity instanceof Proxy) {
</ins>                // We need to initialize entity if we do not miss it's relations
<ins>                $entity = clone($entity);
</ins>            }
             $relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity);
             if ($relatedEntities instanceof Collection || is_array($relatedEntities)) {
                 // If its a PersistentCollection initialization is intended! No unwrap!
}}

As stated by beberlei IIRC, we should add public method to the generated proxy class "**doctrineInitializeProxy" or something

@doctrinebot

Comment created by @beberlei:

Fixed and merged into 2.0.x

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0.6 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment