Failed with: Uncaught Tried to save an object with a pointer to a new, unsaved object

空扰寡人 提交于 2020-01-03 16:43:09

问题


I am having this error, and this is my cloud code.

var HighScore = Parse.Object.extend("HighScore");
highScore = new HighScore();
highScore.set("totalXp", request.params.totalXp);
highScore.set("regionId", request.params.regionId);

var relation = highScore.relation("userId");
relation.add(request.user);

highScore.save();

response.success(highScore);

The response returned empty, but weird thing is, the relation is added successfully when I look at the data browser.

Can't find solid answer or explanation. Please help.


回答1:


I referred to here, and modified my code to it. The reason is because I put creating object and adding relation in 1 save() operation.

var HighScore = Parse.Object.extend("HighScore");
highScore = new HighScore();
highScore.set("totalXp", request.params.totalXp);
highScore.set("regionId", request.params.regionId);

highScore.save(null, {
    success: function(savedHighScore){
            var relation = savedHighScore.relation("userId");
            relation.add(request.user);
            //relation.add(Parse.User.current());
        savedHighScore.save(null, {
            success: function(finalHighScore){
                response.success(finalHighScore);
            },
            error: function(finalHighScore, error){
            }
        });
    },
    error: function(highScore, error){
        console.log("failed to create");
    }
});


来源:https://stackoverflow.com/questions/16514079/failed-with-uncaught-tried-to-save-an-object-with-a-pointer-to-a-new-unsaved-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!