Possible to get previous value of object in Parse Cloud Code AfterSave?

你离开我真会死。 提交于 2019-12-21 22:38:51

问题


I have an AfterSave function that updates something else based on the previous value of the object that was just saved. Simply knowing that the object has changed with object.existed() is not enough.

Is there any way to get the previous value of an object's property without implementing a costly workaround and increasing the number of API calls?

Is it even possible to get the previous value of an object in the AfterSave function?

When I call object.previous("value"), I get an undefined value.


回答1:


Don't know if this is helpful or if it would be considered too costly of a workaround, but you could add a column to the object that is being updated that stores the previous value of the original column. This would allow you to access the previous value in the AfterSave function.




回答2:


Unfortunately I don't have reputation to comment on dstefanis' approach.

This approach is good when one endpoint is changing the value - and indeed I've used it before to this end.

There's a critical limitation in that if multiple endpoints are writing, they may still keep over-writing both the "current" and "old" fields. This means it can't be used to give any strict assurances - e.g. "this field will never be decremented".

A conflict-safe way is to do a parse query by objectId, and pick up the old value. You can then do your own conflict resolution. I have this tested and working :-)



来源:https://stackoverflow.com/questions/26568564/possible-to-get-previous-value-of-object-in-parse-cloud-code-aftersave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!