Parse.com Cloud Code afterSave()错误:“未捕获尝试使用指向未保存新对象的指针保存对象。”

时间:2014-12-23 03:01:43

标签: javascript parse-platform cloud-code after-save

上下文

我在我的后端之后使用 Parse.com 获取Web应用程序。我遇到的问题与 Cloud Code 有关。

用户完成个人资料后,我想调用 afterSave()函数,该函数更新数据集MY_TABLE中的几个字段。

通过输入param01和param02的函数MY_FUNCTION检索要更新的字段(variable01,variable02和variable03)。

错误

我收到以下错误,我无法修复:"未捕获尝试使用指向未保存新对象的指针保存对象。"

代码

Parse.Cloud.afterSave("PROFILE_COMPLETE", function(request) {
    // Use Master Key
    Parse.Cloud.useMasterKey();

    // Identify Parameters in Request
    var param01 = request.user.get('param01');
    var param02 = request.user.get('param02');

    // Print Parameters to Console
    console.log("Parameter 01 (" + param01 + ") successfully identified");
    console.log("Parameter 02 (" + param02 + ") successfully identified");

    // Identify Variables by Calling MY_FUNCTION()
    Parse.Cloud.run('MY_FUNCTION', {param01: param01, param02: param02}, {
        success: function(results) {
            // Print Results
            console.log("Function MY_FUNCTION() returned successful response");
            console.log(results);

            // Print Result Variables
            console.log("Identified variable01 = " + results.variable01);
            console.log("Identified variable02 = " + results.variable02);
            console.log("Identified variable03 = " + results.variable03);

            // Do I need to extend MY_TABLE or something else here???
            // I am doing the update and save wrong...

            // Update 'Complete' Data
            request.object.set("variable01", results.variable01);
            request.object.set("variable02", results.variable02);
            request.object.set("variable03", results.variable03);

            // Save Variables to 'MY_TABLE'
            request.object.save(null, {
                success: function(results) {
                    console.log("Variables successfully updated in MY_TABLE dataset");
                    console.log(results);
                },
                error: function(error) {
                    console.log("Error when saving variables in MY_TABLE dataset");
                    console.log("Error " + error.code + ": " + error.message);
                }
            })
        },
        error: function(error) {
            console.log("There was an error when running function MY_FUNCTION()");
            console.log(error);
        }
    });
});

1 个答案:

答案 0 :(得分:1)

可能在您的说明中遗漏了一些信息,但我希望我以前的经验可以提供帮助:

上次我收到此错误时,我正在执行以下操作:

context:在查询回调中,结果变量为res

var MyParseClass = Parse.Object.extend("MyParseClass");
var newObject = new MyParseClass();

res.set("pointerFieldToMyParseClass",newObject);

res.save();

在此示例中,newObject不存在此函数范围之外的存在,因此您必须先保存它:

var MyParseClass = Parse.Object.extend("MyParseClass");
var newObject = new MyParseClass();

newObject.save({
   success:function(savedObject){

      res.set("pointerFieldToMyParseClass",newObject);
      res.save();

   },error:function(e){}});