Search code examples
parse-platformbefore-save

How to access changed relations in before safe


I would like to track some backend-changes in the cloud.

The log of my before_save tells me something like this:

before_save triggered for Elements for user oKwM9mvEUn:
  Input: {
  "original":
    {"elements":[
        {"__type":"Pointer","className":"Element","objectId":"VzeuG3Z5N6"},
        {"__type":"Pointer","className":"Element","objectId":"APkHJpgcms"},
        {"__type":"Pointer","className":"Element","objectId":"xHG1jg8fny"}
        ]},

    "update":
    {"elements":[
      {"__type":"Pointer","className":"Element","objectId":"VzeuG3Z5N6"},
      {"__type":"Pointer","className":"Element","objectId":"xHG1jg8fny"}
      ]}
    }

  Result: Update changed to 
  {"elements":[
  {"__type":"Pointer","className":"Element","objectId":"VzeuG3Z5N6"},
  {"__type":"Pointer","className":"Element","objectId":"xHG1jg8fny"}
  ]}

The dirtyKeys tells me that "elements" has been changed, but I would like to know what exactly has been added (or removed) because I only like to track the changes...

Is there a possibility to access those "update" values? Or do I have to track it by myself in an other property?

Thanks for a hint!


Solution

  • As I posted on a similar question, you can get relation change details using:

    request.operation.op(yourFieldName)
    

    That returns a Parse.Op.Relation object.