As I noticed, the request.object
in the beforeSave
is already modified. I am investigating the following concept of last update wins:
-
object in database has a nested object with fields and related last update dates. for example
"updated" { "age": "2021-05-7T12:00:00.000Z", "otherField": "2021-05-7T12:00:00.000Z", ... }
-
user A send modified fields with ParseSwift
.save()
and incontext
would be a date set (basically when that update was triggered, and can be also an old date in case or poor connectivity -
in the
beforeSave
trigger the function would go through thedirtyKeys
and compare if the date incontext
is larger than the one in relatedupdates.otherField
-
if the
context
date is lower, it means that the value was updated by a newer one. In this case I would need to throw away that particular field’s update -
if
context
date is larger, theupdates.otherField
date gets set to the same value as in thecontext
what would be a reasonable way to do?
-
set that field value from the
original
object in that beforeSave trigger? -
use
revert(…keys)
function in that beforeSave trigger? -
is there any smarter way how to implement some kind of simple last update wins?
Thank you!