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

Closed
opened 2026-01-22 13:16:18 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 3, 2011).

Originally assigned to: @beberlei on GitHub.

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

Originally created by @doctrinebot on GitHub (Jun 3, 2011). Originally assigned to: @beberlei on GitHub. 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
admin added the Bug label 2026-01-22 13:16:18 +01:00
admin closed this issue 2026-01-22 13:16:19 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2011):

@doctrinebot commented on GitHub (Jun 3, 2011): - depends on [DDC-733: Implement a way of forcing a PersistentCollection to initialize itself](http://www.doctrine-project.org/jira/browse/DDC-733)
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2011):

Comment created by xanf:

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

@doctrinebot commented on GitHub (Jun 3, 2011): Comment created by xanf: Test case. Expected to be put into Tests/ORM/Functional/Ticket folder
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2011):

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 commented on GitHub (Jun 3, 2011): 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
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2011):

Comment created by @beberlei:

Fixed and merged into 2.0.x

@doctrinebot commented on GitHub (Jun 5, 2011): Comment created by @beberlei: Fixed and merged into 2.0.x
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jun 5, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/5dc5613ebbbb0ff6f030

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/5dc5613ebbbb0ff6f030 - [10997_DDC1193Test.php](https://gist.github.com/5dc5613ebbbb0ff6f030#file-10997_DDC1193Test-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1502