问题
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