I have a Doctrine model that I would like to protect using optimistic locking. The version field I am using is a DateTime - unfortunately, because this is only precise to the second, the built-in Doctrine versioning does not work if multiple queries are executed at the same second.
To fix this, I have created a query that uses NOW(6), which has microsecond precision:
UPDATE thing
SET count = count + 1, modified_at = NOW(6)
WHERE modified_at = ?
I would like this query to be used when I call $thing_repository->save($thing). How can I register a custom update query (or function) to be called when the entity is saved, instead of the built-in persister->update($entity)?