mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Updating a not modified field in preUpdate event #6900
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mmarton on GitHub (Jan 9, 2022).
Bug Report
Hi!
this is either a documentation issue or a code one or a support question :D
Summary
I want to change a field that in preUpdate event that is not in the changeset.
Current behavior
https://github.com/doctrine/orm/blob/2.10.x/docs/en/reference/events.rst#preupdate
The docs sais at the limitations part:
I can't use the
setNewValuemethod because it only works for values that are in the computed changeset.But setting it on the entity works... so
@teamore commented on GitHub (Jan 10, 2022):
Same issue here. It seems that you can only modify fields that are already scheduled for Update when using the PreUpdate-hook provided by doctrine. Changes to the respective entity by $entity->setField() are ignored whereas $eventArgs->setNewValue($field, $value) results in an error if the field has not already been changed before the listener is called.
I would also appreciate an answer to this issue/lack of clarity.
@teamore commented on GitHub (Jan 10, 2022):
I found out that when I recalculate the ChangeSet (from UnitOfWork) after having applied the desired changes to the entity, the update also includes the changes applied inside the PreUpdate-listener.
Therefore, if we are dealing with a doctrine document (ODM), you need to recalculate the UOW-ChangeSet after setting the value for the field via:
$om = $args->getObjectManager(); $om->getUnitOfWork()->recomputeSingleDocumentChangeSet($om->getClassMetadata($entity::class), $entity);@mmarton commented on GitHub (Jan 26, 2022):
@beberlei can you help me with this question? :)
@mmarton commented on GitHub (May 9, 2022):
Anyone can help me out with this?
@EwenQuim commented on GitHub (Jun 5, 2023):
I'd like to know if any solution has been found since last year ! Thanks