mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[Feature Request] Increment update #5750
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 @wlzch on GitHub (Oct 24, 2017).
Originally assigned to: @Ocramius on GitHub.
It will be a good addition to enable increment update because there is a problem with concurrent update now (I avoid using locking mechanism to provide a better experience for user).
For example:
I have a quantityLeft field in an Item entity which will be decremented on every purchase. But if there are 2 users purchasing the same Item on the same time, quantityLeft will be updated to the last successful update. If it is possible to specify a column as "increment update", then this will solve the problem as the update query will be "quantityLeft = quantityLeft - 1" instead of "quantityLeft = value".
If there's a pointer on how/where to add this feature, I'll try to make a PR. Thanks.
@Ocramius commented on GitHub (Oct 24, 2017):
@wlzch running plain SQL is pretty much OK in this case - what kind of abstraction are you looking for?
@wlzch commented on GitHub (Oct 24, 2017):
Probably adding it on Column annotation.
Column(type="int", increment=true)Running plain SQL is not possible for my case as I wrap multiple inserts and updates in 1 transaction. If I try to run the plain increment update, the ORM will still update the quantityLeft value when flushing.
@Ocramius commented on GitHub (Oct 24, 2017):
Oh, you mean in ORM? That is not possible: ORM will only ever mirror in-memory state with DB state, as changing anything DB-side without performing another lookup that refreshes your entity state.
@Ocramius commented on GitHub (Oct 24, 2017):
Closing as
can't fix