解析云“beforeSave”不保存数据

时间:2016-03-08 22:08:06

标签: parse-platform parse-javascript-sdk

我正在使用解析 beforeSave 方法来保存订单,以下是代码:

    //Before save an order - if finish - set priority to 0
    Parse.Cloud.beforeSave("UserToOrders", function(request, response) {
    Parse.Cloud.useMasterKey();
    var preStatus = request.object.get("OrderStatus");
    if (preStatus == "Finish") {
        request.object.set("Priority",0);
        console.log("beforeSave(\"UserToOrders\")\t Order (" + request.object.id + ") Status is 'Finish' So Priority set to '0'");
    }
    else {
        console.log("beforeSave(\"UserToOrders\")\t Order (" + request.object.id + ") Status Changed to: " + preStatus);
        request.object.set("OrderStatus",preStatus);

    }
    response.success();
});

这是日志:

I2016-03-09T20:56:05.779Z]v136 before_save triggered for UserToOrders for user pSi0iCGJJe:
  Input: {"original":{"ACL":{"*":{"read":true},"vxgEWFQ7eu":{"read":true,"write":true}},"OrderStatus":"Ready","OrderStatusActivity":"Active","ResturantID":"g1bzMQEXoj","TimeToBeReady":{"__type":"Date","iso":"2016-03-08T23:35:23.916Z"},"UserETA":{"__type":"Date","iso":"2016-03-08T23:35:23.916Z"},"UserID":"vxgEWFQ7eu","createdAt":"2016-03-08T21:06:06.605Z","objectId":"t3NoxcSp5z","updatedAt":"2016-03-08T21:40:59.538Z"},"update":{"OrderStatus":"Finish","objectId":"t3NoxcSp5z"}}
  Result: Update changed to {"OrderStatus":"Finish","Priority":0}

I2016-03-09T20:56:05.975Z]beforeSave("UserToOrders")     Order (t3NoxcSp5z) Status is 'Finish' So Priority set to '0'

但是数据库中没有任何改变。

我错过了什么?

感谢。

2 个答案:

答案 0 :(得分:0)

var preStatus中的

与您想要保存的值相同...

var preStatus = request.object.get("OrderStatus");

你是"拯救"相同的值,你可以删除这一行

request.object.set("OrderStatus",preStatus);

如果不是您想要的,请提供来自" OrderStatus"的日志。 =完成

答案 1 :(得分:0)

我已经弄清楚了。这是一个ACL权限问题。 由一个客户创建的订单,而另一个客户创造的机会。