Parse cloudcode beforeSave obtain pre-updated object

前端 未结 5 1967
独厮守ぢ
独厮守ぢ 2020-12-06 11:56

In a beforeSave hook I want to obtain the state of the object prior to the update. In this particular case it is to stop a user from changing their choice once

5条回答
  •  一整个雨季
    2020-12-06 12:48

    You can use Parse DirtyKeys to identify which field has changed.

       Parse.Cloud.beforeSave(Parse.User, function(request, response) {
      for (dirtyKey in request.object.dirtyKeys()) {
        if (dirtyKey === "yourfieldname") {
          response.error("User is not allowed to modify " + dirtyKey);
          return;
        }
      }
      response.success();
    });
    

提交回复
热议问题