我试图通过云代码检索一本书的作者,但我一直收到错误。这是我的代码:
//Retrieve Request Parameter
bookId = request.params.bookId;
//Create an empty Book Object
var book = new Parse.Object("Book");
book.id = bookId;
//Define Book Relation
var bookRelation = book.relation("authors");
//Define Query
var query = bookRelation.query();
query.find ({
success: function(books) {
//Return Response
response.success(books);
},
error: function(error) {
//Return Response
response.error(error);
}
});
正确传递了id(通过登录到控制台进行了检查),但错误似乎发生在以下行:var query = bookRelation.query();
。
答案 0 :(得分:0)
我会说因为没有填充对象上的Relation信息,显然你无法构建一个查询来访问它的Relation数据。您最好先加载对象,然后尝试访问其关系数据:
var query = new Parse.Query("Book");
query.get(request.params.bookId).then( function(book) {
var bookRelation = book.relation("authors").query();
return bookRelation.find();
}).then( function(authors) {
response.success(authors);
}, function(error) {
response.error(error);
});