4 ms·
No need for a workaround, you have Optimistic Locking (via lock_version field) It raises an exception in case you try to update stale data. http://api.rubyonr
by amikazmi 14y ago
No need for a workaround, you have Optimistic Locking (via lock_version field)
It raises an exception in case you try to update stale data.
http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html http://api.rubyonrails.org/classes/ActiveRecord/Locking/Opti...
- EvilTrout 14y agoRight, but that involves changing your database and adding hidden form fields to your app in order for it to work on a multi process environment (like every production server should be.) My solution is basically the same amount of lines, requires no such changes.
- gnaritas 14y agoYes, but optimistic locking with a version is the general and known solution to this problem in all cases and is built into the framework already. Your solution works in just one case, not the general case.
- amichal 14y agoOr no table changes with http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pess... but in this specific case `affected_rows` works better as long as you know its reliable.
- deleted 14y ago[deleted]