This question is really language- and framework-neutral, but since we’re here, and I’m using ZF3 + Doctrine:
I have a situation where we want to avoid the lost update problem – e.g., Bob loads /entities/edit/123 at the same time as Alice, and Bob changes foo to bar, and Alice changes baz to bat, and Bob hits save, and then Alice hits save and blows away Bob’s update.
Wait – come to think of it, I believe (having stared at a lot of SQL logs) that under the hood Doctrine is clever enough to only do UPDATE entity SET foo = ‘bar’ and leave the rest untouched. True? So in the above case this wouldn’t be a problem. So let’s suppose they edited the same attribute and you have a conflict. (Or let’s suppose you’re lazy like me and really don’t want the task of keeping track of who modified what.)
What I have been doing is a technique I learned a long time ago: your entity has a last_modified attribute, you load its value into the form as a hidden field, and at update time you fetch it again and compare. If it’s the same, carry on; if not, abort the UPDATE with a message saying sorry, it seems another user/process has modified this record in the time since you loaded it, please reload and try again. And I think I’ve used apps that do this very thing.
(I’ve read that people sometimes also have a
version column that they increment with each update and use that instead of a timestamp, but the concept is the same.)
Now, I have a user complaining that when this happens, it is too great an inconvenience, and that instead what I should do is track who is currently editing what, and if an edit is in progress on entity #123, don’t let anyone else load /entities/edit/123, but give them a message instead saying somebody else is working on this, please wait (or go talk to her/him and say get on with it). So I set about reading about how to implement this, and it’s rather onerous, and raises some potential problems of its own.
So, the question: in general terms, how do you usually handle this, and what do you suggest?