mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Dynamically disable Optimistic Locking #7283
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 @ilconfo on GitHub (Dec 18, 2023).
Feature Request
Dynamically disable Optimistic Locking
Summary
Hello,
thanks for your hard work, and for this fantastic library.
I've searched a lot but I couldn't find a method to disable optimistic/pessimistic locking. I report at the end of the comment the changes.
The rationale is this: in some projects I almost always want to keep using optimistic locking to protect entities from overwriting data if two users are working on the same entity at the same time.
But sometimes I would like to change some accessory fields in the same entity, for example using a command in a cronjob, and sometimes when I do that the command updates the entity while a user is changing it. So, the user will get an OptimisticLockException.
This is not always desiderable, for instance I could be calculating some field that is updatable only by the command, because the users will only read it (e.g. like a summation of totals linked to the entity).
I could do this using Native SQL, but I've found that changing at this line
/var/www/capitolium/backend/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:3479
From
To
$this->requiresFetchAfterChange = $bool;It is possible to dynamically disable Optimistic Locking in a command, using:
Could be this possibility useful for the library?
Thanks
Claudio