gpt4 book ai didi

parse-platform - 错误 : 101 object not found for update

转载 作者:行者123 更新时间:2023-12-02 07:03:24 24 4
gpt4 key购买 nike

我有以下 parse.com 云代码

Parse.Cloud.afterSave("Action", function (request) {

var BookStatus = Parse.Object.extend("BookStatus");
var Book = Parse.Object.extend("Book");
var book = new Book();

var actionType = request.object.get("actionTypePointer").id;
var bookId = request.object.get("bookPointer").id;

var queryBook = new Parse.Query("Book");
var newBookStatus;

queryBook.get(bookId,{
success: function (gottenBook) {

newBookStatus = "idOfTheBookStatus";

book.id = bookId;
book.set("bookStatus", new BookStatus({id: newBookStatus}));
gottenBook.set("bookStatus", new BookStatus({id: newBookStatus}));

//OPTION 1
gottenBook.save(null,{
success: function(data) {
console.log("Bookstatus updated1");
},
error: function (data,error) {
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}
});
//OPTION 2
book.save(null,{
success: function(data) {
console.log("Bookstatus updated2");
},
error: function (data,error) {
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}
});

},
error: function (object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}

});

选项1我尝试在将 bookStatus 设置为返回的书后保存查询的书。

选项2我尝试在设置 book.Id 后保存新书对象

        book.id = bookId;
book.set("bookStatus", new BookStatus({id: newBookStatus}));

然而,使用这两个选项中的任何一个,我最终都会进入 parse.com 日志:

错误:101 找不到要更新的对象 错误:101 找不到要更新的对象

知道我做错了什么吗?

提前致谢!

--编辑

使用 fetch 的新实现:

Parse.Cloud.afterSave("Action", function (request) {

var BookStatus = Parse.Object.extend("BookStatus");
var Book = Parse.Object.extend("Book");
var book = new Book();

var actionType = request.object.get("actionTypePointer").id;
var bookId = request.object.get("bookPointer").id;

book.id = bookId;
console.log("before fetch book.id" + book.id);
var newBookStatus;

book.fetch({
success: function (book) {
newBookStatus = "XMFkXS9NVv";

book.set("bookStatus", new BookStatus({id: newBookStatus}));

console.log("book" + book);
console.log("book.id" + book.id);
console.log("book.isValid()" + book.isValid());

book.save(null,{
success: function(data) {
console.log("Book Status updated to:" +newBookStatus);
},
error: function (data,error) {
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}
});
},
error: function (object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}

});

});

结果:

  Input: {"place":{"__type":"GeoPoint","latitude":41.354643806134625,"longitude":2.121594674804572},"bookLocationDescription":"sad","bookPointer":{"__type":"Pointer","className":"Book","objectId":"kWcALge4az"},"actionTypePointer":{"__type":"Pointer","className":"ActionType","objectId":"kJC954w9iO"},"userPointer":{"__type":"Pointer","className":"_User","objectId":"6xpiAHX9Ju"},"createdAt":"2013-05-16T13:59:33.810Z","updatedAt":"2013-05-16T13:59:33.810Z","objectId":"PwlXhKL51l","ACL":{"6xpiAHX9Ju":{"read":true,"write":true},"*":{"read":true}}}
Result: Success

I2013-05-15T20:52:19.170Z] before fetch book.idc1iKxw3NLD
I2013-05-15T20:52:19.273Z] book[object Object]
I2013-05-15T20:52:19.273Z] book.idc1iKxw3NLD
I2013-05-15T20:52:19.273Z] book.isValid()true
I2013-05-15T20:52:19.325Z] Error: 101 object not found for update

最佳答案

您的 afterSave Hook 正在覆盖获取的 Book 的对象 ID。即使您在其上设置了相同的对象 ID,该对象现在也会认为它是脏的并且不再是有效的引用。

通过使用 get() 返回的书并且不更新它的 id 来避免这种情况:

    Parse.Cloud.afterSave("Action", function (request) {

var BookStatus = Parse.Object.extend("BookStatus");
var Book = Parse.Object.extend("Book");
var book = new Book();

var actionType = request.object.get("actionTypePointer").id;
var bookId = request.object.get("bookPointer").id;

var queryBook = new Parse.Query("Book");

var newBookStatus;

queryBook.get(bookId,{
success: function (book) {
newBookStatus = "idOfTheBookStatus";

book.set("bookStatus", new BookStatus({id: newBookStatus}));

book.save(null,{
success: function(data) {
console.log("Bookstatus updated1");
},
error: function (data,error) {
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}
});
},
error: function (object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}

});
});

由于您已经知道这本书的 ID,因此您可以创建一个指针并直接获取它,而不是使用查询。

最后的 afterSave Hook :

    Parse.Cloud.afterSave("Action", function (request) {

var BookStatus = Parse.Object.extend("BookStatus");
var Book = Parse.Object.extend("Book");
var book = new Book();

var actionType = request.object.get("actionTypePointer").id;
var bookId = request.object.get("bookPointer").id;

book.id = bookId;

var newBookStatus;

book.fetch({
success: function (book) {
newBookStatus = "idOfTheBookStatus";

book.set("bookStatus", new BookStatus({id: newBookStatus}));

book.save(null,{
success: function(data) {
console.log("Bookstatus updated1");
},
error: function (data,error) {
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}
});
},
error: function (object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
console.log("Error: " + error.code + " " + error.message);
}

});
});

关于parse-platform - 错误 : 101 object not found for update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com