The ultimate goal is to detect changes between an existing Parse object and the incoming update using the beforeSave
function in Cloud Code.
From the Cloud Code log available through parse.com, one can see the input to beforeSave
contains a field called original
and another one called update
.
Cloud Code log:
Input: {"original": { ... }, "update":{...}
I wonder if, and how, we can access the original field in order to detect changing fields before saving.
Note that I've already tried several approaches for solving this without success:
- using (object).changedAttributes()
- using (object).previousAttributes()
- fetching the existing object, before updating it with the new data
Note on request.object.changedAttributes()
:
returns false
when using in beforeSave and afterSave -- see below for more details:
Log for before_save
-- summarised for readability:
Input: { original: {units: '10'}, update: {units: '11'} }
Result: Update changed to { units: '11' }
[timestamp] false <--- console.log(request.object.changedAttributes())
Log for corresponding after_save
:
[timestamp] false <--- console.log(request.object.changedAttributes())