如何获取 Parse 对象并包含对象引用?
How to fetch a Parse object and include object references?
能否使用 object.fetch
获取 Parse 对象,同时像 query.include
那样包含其对象引用?
查询示例如下:
let query = new Parse.Query("MyCollection");
query.include("MyObjectReference");
return query.find();
如何使用获取命令来完成?
解析 JS SDK >= 2.0.2
可以使用 include 获取一个或多个对象:
fetchWithInclude
https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html#fetchWithInclude
fetchAllWithInclude
https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html#.fetchAllWithInclude)
解析 JS SDK < 2.0.2
不可能像docs说的那样:
By default, when fetching an object, related Parse.Objects are not
fetched. These objects’ values cannot be retrieved until they have
been fetched like so:
var post = fetchedComment.get("parent");
post.fetch({
success: function(post) {
var title = post.get("title");
}
});
Parse 中的获取命令本质上是一个在单个对象 ID 上只有 "where equal to" 的查找。因此,您可以简单地查询单个对象 ID,Parse 将像提取一样处理它,例如您可以将 table 限制为仅允许获取,并且此单个对象 ID 查询仍将通过。我没有读过代码,但我相信提取本质上是一个单一的对象 ID(查找)查询。然后,您还可以使用查找查询的包含。
通过 google 搜索偶然发现了这一点,并希望更正记录。接受的答案是不正确的。
你可以通过使用 fetchWithInclude([key1,key2.subkey,key2.subkey2,etc]);
来完成 OP 要求的事情
参见:https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html
能否使用 object.fetch
获取 Parse 对象,同时像 query.include
那样包含其对象引用?
查询示例如下:
let query = new Parse.Query("MyCollection");
query.include("MyObjectReference");
return query.find();
如何使用获取命令来完成?
解析 JS SDK >= 2.0.2
可以使用 include 获取一个或多个对象:
fetchWithInclude
https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html#fetchWithIncludefetchAllWithInclude
https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html#.fetchAllWithInclude)
解析 JS SDK < 2.0.2
不可能像docs说的那样:
By default, when fetching an object, related Parse.Objects are not fetched. These objects’ values cannot be retrieved until they have been fetched like so:
var post = fetchedComment.get("parent"); post.fetch({ success: function(post) { var title = post.get("title"); } });
Parse 中的获取命令本质上是一个在单个对象 ID 上只有 "where equal to" 的查找。因此,您可以简单地查询单个对象 ID,Parse 将像提取一样处理它,例如您可以将 table 限制为仅允许获取,并且此单个对象 ID 查询仍将通过。我没有读过代码,但我相信提取本质上是一个单一的对象 ID(查找)查询。然后,您还可以使用查找查询的包含。
通过 google 搜索偶然发现了这一点,并希望更正记录。接受的答案是不正确的。
你可以通过使用 fetchWithInclude([key1,key2.subkey,key2.subkey2,etc]);
参见:https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html