ミームの例を読んだことがありますが、更新されていないようです。新しいオブジェクトを作成するだけです! 私がしたいのは
a. find some given db table
b. update some fields in the db table
c. save the db table back to the database
このコードを考えると、実際にオブジェクトを更新できるようにするために欠けている部分は何ですか?
query.find(
function(results){
if (results.length > 0){
return results[0];
} else {
//no object found, so i want to make an object... do i do that here?
return null;
}
},
function(error){
response.error("ServerDown");
console.error("ServerDown - getModuleIfAny URGENT. Failed to retrieve from the ModuleResults table" + +error.code+ " " +error.message);
}
).then(
function(obj){
var module;
if (obj != null){
console.log("old");
module = obj;
module.moduleId = 10; //let's just say this is where i update the field
//is this how i'd update some column in the database?
} else {
console.log("new");
var theModuleClass = Parse.Object.extend("ModuleResults");
module= new theModuleClass();
}
module.save().then(
function(){
response.success("YAY");
},
function(error) {
response.error('Failed saving: '+error.code);
}
);
},
function(error){
console.log("sod");
}
);
上記のコードは機能すると思いましたが、機能しません。オブジェクトが見つかると、代わりに保存を拒否し、私のオブジェクトには「保存」メソッドがないことを愚かにも教えてくれます。