[Feature Request] Increment update #5750

Closed
opened 2026-01-22 15:16:25 +01:00 by admin · 4 comments
Owner

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.

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.
admin added the New FeatureCan't FixQuestion labels 2026-01-22 15:16:25 +01:00
admin closed this issue 2026-01-22 15:16:25 +01:00
Author
Owner

@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?

@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?
Author
Owner

@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.

@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.
Author
Owner

@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): 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.
Author
Owner

@Ocramius commented on GitHub (Oct 24, 2017):

Closing as can't fix

@Ocramius commented on GitHub (Oct 24, 2017): Closing as `can't fix`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5750