How to check if another user has changes a record

Hi
What’s the simplest way to check if a user has changed a record?

User “A” starts to edit a record
User “B” starts to edit the same record and saves first
User “A” no longer has the most up to date record

How can I check to see there isn’t a more recent copy of the file before saving?

One simple solution:

  • add the timestamp behavior
  • add modified as hidden field to the form
  • validate the existing modified against the one send

Thanks - will give that a go. I am using timestamp behaviour - forgot to add modified as a hidden field and wondering why it didn’t work!

You can also enable more sophisticated logging/audit plugins here to keep track of modifications.

thanks - will be adding back some sort of logging.

What we had in our CakePHP 2 app was a simple behaviour that added optimistic locking - stored in a virtual field the modified date and on saving checked that to the current modified date. If it’s different someone else was editing the record as well and saved it - popped up a message like

The record was updated while you were on this page. Please confirm you want to overwrite those changes by submitting again.

never mind - think I found what I want :slight_smile: