Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1193

cascadeRemove misses associations due to proxy not being initialized

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.5, Git Master
    • Fix Version/s: 2.0.6, 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux x86_64

      Description

      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

        Issue Links

          Activity

          Hide
          Illya Klymov added a comment -

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

          Show
          Illya Klymov added a comment - Test case. Expected to be put into Tests/ORM/Functional/Ticket folder
          Hide
          Illya Klymov added a comment -

          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
          +++ b/lib/Doctrine/ORM/UnitOfWork.php
          @@ -1702,7 +1702,10 @@ class UnitOfWork implements PropertyChangedListener
                       if ( ! $assoc['isCascadeRemove']) {
                           continue;
                       }
          -            //TODO: If $entity instanceof Proxy => Initialize ?
          +            if ($entity instanceof Proxy) {
          +                // We need to initialize entity if we do not miss it's relations
          +                $entity = clone($entity);
          +            }
                       $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

          Show
          Illya Klymov added a comment - 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 +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1702,7 +1702,10 @@ class UnitOfWork implements PropertyChangedListener if ( ! $assoc['isCascadeRemove']) { continue ; } - //TODO: If $entity instanceof Proxy => Initialize ? + if ($entity instanceof Proxy) { + // We need to initialize entity if we do not miss it's relations + $entity = clone($entity); + } $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
          Hide
          Benjamin Eberlei added a comment -

          Fixed and merged into 2.0.x

          Show
          Benjamin Eberlei added a comment - Fixed and merged into 2.0.x

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Illya Klymov
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: