Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-1690

Notify policy listeners are not attached to entities with Notify policy


    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.3.2
    • Component/s: ORM
    • Security Level: All
    • Labels:


      It seems that it happens because the UnitOfWork::addToIdentityMap() is not the only way to add an entity to the identity map. It is possible to do it directly by assigning array values (pulling my hair why?) . But the code in that method also adds a property changed listener to an entity. As a result that entity is not persisted properly as it does not have a listener. I spent a lot of time trying to figure out why some of my entities were persisted and others no. That happens for entities of same class with parent - children associations.

      Probably the notify policy is not very popular otherwise the bug would have been reported long time ago.

      Adding these lines to the UnitOfWork at line 2004 fixes the issue:

          // PERF: Inlined & optimized code from UnitOfWork#registerManaged()
          $newValueOid = spl_object_hash($newValue);
          $this->entityIdentifiers[$newValueOid] = $associatedId;
          $this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
          // new lines
       -- if ($newValue instanceof NotifyPropertyChanged) {
       --     $newValue->addPropertyChangedListener($this);
       -- }
          //end of new lines
          $this->entityStates[$newValueOid] = self::STATE_MANAGED;
          // make sure that when an proxy is then finally loaded, $this->originalEntityData is set also!



          • Assignee:
            beberlei Benjamin Eberlei
            deatheriam Oleg Namaka
          • Votes:
            1 Vote for this issue
            2 Start watching this issue


            • Created: