失败:未捕获尝试使用指向未保存的新对象的指针保存对象 [英] Failed with: Uncaught Tried to save an object with a pointer to a new, unsaved object

查看:287
本文介绍了失败:未捕获尝试使用指向未保存的新对象的指针保存对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误,这是我的云代码。

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 save()操作中创建对象和添加关系。

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");
    }
});

这篇关于失败:未捕获尝试使用指向未保存的新对象的指针保存对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆