Skip to content

Loading…

DDC-534: UnitOfWork propertyChanged does nto check if the notified model property is one being persisted #5043

Closed
doctrinebot opened this Issue · 2 comments

1 participant

@doctrinebot

Jira issue originally created by user disago:

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.

@doctrinebot

Comment created by romanb:

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.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-BETA2 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.