I have job collection and it has a field applicants which is Relation type of class User. Now I want to send a push notification to a user when an operation like AddRelation or RemoveRelation happens on the applicants field. Parse Object has following two methods available by which I can understand If i should send a push. these two methods are the following.
req.object.dirtyKeys()
req.object.op('applicants')
These two functions returns me expected result on beforeSave hook. I get an empty result in afterSave which is by documentation as expected.
Now my problem is I don't want to send push in beforeSave as there might be other validation logic comes up which eventually cancels the operation. I want send push only when the object is saved and the above condition met. Is there anything like to pass data from beforeSave to afterSave. Or am I missing something obvious?
An easy -- although not too elegant -- way to pass data between
beforeSaveandafterSaveis to set a property on the object being saved. When you save the object and don't want to pass any info, unset it; else set a value which can be interpreted byafterSave. Unfortunately you cannot easily clear the property inafterSavebecause this would cause a new save and thus triggerbeforeSaveagain, so the rest of the application should ignore that property...