Reputation: 744
I have an preUpdate Eventlistener on an Entitychild in my embedded Form.
I can change the attribute related to my entity:
public function preUpdate(LifecycleEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
$em = $eventArgs->getEntityManager();
if ($entity instanceof AOSupplierReference) {
if ($eventArgs->hasChangedField('amount')) {
$entity->setConfirmed(false);
}
}
}
But now I have to change an attribute of the parent Entity, this don't work in my preUpdate event:
$entity->getPurchaseOrder()->setStatus(4);
only the $entity->setConfirmed(false) changes.
Upvotes: 1
Views: 592
Reputation: 52513
You can't update a related entity in a preUpdate listener:
PreUpdate is the most restrictive to use event, since it is called right before an update statement is called for an entity inside the EntityManager#flush() method.
Changes to associations of the updated entity are never allowed in this event, since Doctrine cannot guarantee to correctly handle referential integrity at this point of the flush operation.
See the documentation.
Upvotes: 3