Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-534

UnitOfWork propertyChanged does nto check if the notified model property is one being persisted

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-BETA2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      When a Model implements NotifyPropertyChanged interface it may use the registered listeners for other purposes beyond the ORM and when the property being notified is not managed by Doctrine it will rise an undefined index propertyName PHP warning when trying to execute the updates.

      Proposed solution:

      Change UnitOfWork::propertyChanged to check whether the notified property is part of entitiy's metadata (right now it only checks if the property has association mappings and if not it just adds the entity to $this->_entityUpdates) :

      public function propertyChanged($entity, $propertyName, $oldValue, $newValue) {
      /* .. code ... */ 
              } else {
                  $this->_entityUpdates[$oid] = $entity;
              }
      }
      

      to

      public function propertyChanged($entity, $propertyName, $oldValue, $newValue) {
      /* .. code ... */ 
              } elseif ($class->hasField($propertyName)) {
                  
                  $this->_entityUpdates[$oid] = $entity;
              }
      }
      

      NOTE: If the propertyChanged is modified this way the entity will not fire lifecycle events if only that property is modified. Maybe a better solution is to fire the lifecycle events (if any) but if the property is not being persisted then do not try to update it.

        Activity

        Hide
        Roman S. Borschel added a comment -

        That lifecycle events would not fire would be correct. Doctrine should not care about non-persistent state. It does not do that with the other change-tracking policies, too.

        Thanks for the report! I will fix that soon.

        Show
        Roman S. Borschel added a comment - That lifecycle events would not fire would be correct. Doctrine should not care about non-persistent state. It does not do that with the other change-tracking policies, too. Thanks for the report! I will fix that soon.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Diego Sainz
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: