In my parse-server cloud code, I have one beforeSave and one afterSave function. The beforeSave is a verification about "which user makes the saving" to the "post" table. The afterSave function upates an object in the "post" table when a comment is saved to the "comments" table. However, the "result[0].save(null, { useMasterKey: true });" part start the beforeSave function again, and as the cloud is doing the saving and there is no user, because of the user verification in the "beforeSave" part, the saving can not be done. It is a bit complicated, hope I could explained it well, is there a way to by pass the beforeSave method when the saving is done from the cloud?
Parse.Cloud.beforeSave('post', function (req, res) {
});
Parse.Cloud.afterSave('comment', function(req) {
var post = Parse.Object.extend('post');
var query = new Parse.Query(post);
query.equalTo('userid', req.user.id);
query.find({
success: function(result) {
if ( result.length > 0 ) {
result[0].set('commented', 'yes');
result[0].save(null, { useMasterKey: true });
}
else {
}
}
});
});