解析 - 无法从安装类获取和更新列

时间:2016-08-21 22:23:21

标签: javascript parse-platform

我正在尝试使用约束Parse.Installationquery.equalTo("installationId", uuid);类获取数据,然后,当我想更新我在成功回调中获得的行时;但是,我无法这样做,到目前为止我没有收到任何错误。

我正在从云代码执行它。

以下是代码:

Parse.Cloud.define("updateInstallationClass", function(request, response) {

var uuid = request.params.uuid;
var userID = request.params.userID;
  var GameScore = Parse.Object.extend(Parse.Installation);
        var query = new Parse.Query(GameScore);
        query.equalTo("installationId", uuid);
        query.first({useMasterKey:true},{
          success: function(object22) {
            // Successfully retrieved the object.
              object22.set("userID3", userID);
              object22.save(null, {useMasterKey:true});
             console.log("userID3", userID);
            console.log('success ', object22);
          },
          error: function(error) {
            alert("Error: " + error.code + " " + error.message);
          }
        });
   });

1 个答案:

答案 0 :(得分:1)

如果要更新Parse.Installation条目,则必须在 ParseObject.save() 之前调用以下函数:

Parse.Cloud.useMasterKey();

结果代码:

Parse.Cloud.define("updateInstallationClass", function(request, response) {

    var uuid = request.params.uuid;
    var userID = request.params.userID;
    var GameScore = Parse.Object.extend(Parse.Installation);

    var query = new Parse.Query(GameScore);
    query.equalTo("installationId", uuid);
    query.first({useMasterKey:true},{
        success: function(object22) {
            // Successfully retrieved the object.

            // >>>>>>>>>>>>>>>>>>>>>>>>>
            Parse.Cloud.useMasterKey();
            // <<<<<<<<<<<<<<<<<<<<<<<<<

            object22.set("userID3", userID);
            object22.save(null, {useMasterKey:true});
            console.log("userID3", userID);
            console.log('success ', object22);
        },
        error: function(error) {
            alert("Error: " + error.code + " " + error.message);
        }
    });
});

编辑1:

在第一行调用Parse.Cloud.useMasterKey();,然后执行查询。 您的安装表没有读取权限。

Parse.Cloud.define("updateInstallationClass", function(request, response) {

    // >>>>>>>>>>>>>>>>>>>>>>>>>
    Parse.Cloud.useMasterKey();
    // <<<<<<<<<<<<<<<<<<<<<<<<<

    var uuid = request.params.uuid;
    var userID = request.params.userID;
    var GameScore = Parse.Object.extend(Parse.Installation);

    var query = new Parse.Query(GameScore);
    query.equalTo("installationId", uuid);
    query.first({useMasterKey:true},{
        success: function(object22) {
            // Successfully retrieved the object.

            object22.set("userID3", userID);
            object22.save(null, {useMasterKey:true});
            console.log("userID3", userID);
            console.log('success ', object22);
        },
        error: function(error) {
            alert("Error: " + error.code + " " + error.message);
        }
    });
});

编辑2:

要保存指针值,您必须创建该类的新实例并分配objectId。

Parse.Cloud.define("updateInstallationClass", function(request, response) {

    // >>>>>>>>>>>>>>>>>>>>>>>>>
    Parse.Cloud.useMasterKey();
    // <<<<<<<<<<<<<<<<<<<<<<<<<

    var uuid = request.params.uuid;
    var userID = request.params.userID;
    var GameScore = Parse.Object.extend(Parse.Installation);

    var query = new Parse.Query(GameScore);
    query.equalTo("installationId", uuid);
    query.first({useMasterKey:true},{
        success: function(object22) {
            // Successfully retrieved the object.

            var user = new Parse.User();
            user.set("objectId", userID);
            object22.set("userID3", user);

            object22.save(null, {useMasterKey:true});
            console.log("userID3", userID);
            console.log('success ', object22);
        },
        error: function(error) {
            alert("Error: " + error.code + " " + error.message);
        }
    });
});

编辑3:

替换:

var user = new Parse.User();
user.set("objectId", userID);

使用:

var UserObj = Parse.Object.extend("User");
var user = new UserObj();
user.id = userID;