0

I'm trying to check the current and previous value of an attribute in the beforeSave(). So i tried to use request.object.previous("attribute_name") but it is still returning the current changed value. Although the .ditry() is returning TRUE which means that the value is changed. Any idea what is wrong here ? I appreciate your feedback.

1 Answers1

1

I think the .previous() isn't actually part of the Parse.com sdk, but simply inherited from backbone.

In a beforeSave handler, I have something like:

if(object.dirty("attr")) { 
   console.log("After: " + object.get("attr") + ", Before: " + object.previous("attr")); }

The value returned by 'previous' is always the same. Is this functionality actually implemented? I've seen a few threads elsewhere that imply it's not - if so, can you remove it from the API docs until it's done?

If it doesn't work, is the correct workaround to query the previous object? Or does 'changedAttributes' work? Oh, I now see that 'previous' is some cruft from Backbone.

source1

previous is a method inherited from Backbone.Model. It won't return the previous value of a field in Cloud Code.

source2

Might not be the answer you're looking for, so as a way to workaround the lack of the .previous implementation this this out:

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.

Community
  • 1
  • 1
Bart de Ruijter
  • 917
  • 10
  • 21