繁体   English   中英

解析 - 获取父项与其子项在数组中的一对多关系

[英]Parse - get parent items with their child items in array one to many relation

我的Parse模式中有以下关系:“Post”项目带有“Comments”子项。 我正在使用Arrays for One-to-Many Relations,如下所述: relations_guide

如何获取所有帖子(即使没有评论的帖子)以及每篇帖子的所有评论?

我正在尝试这样的事情:

var post = Parse.Object.extend("post");
var comment = Parse.Object.extend("comment");

var queryPosts = new Parse.Query(post);
var queryComments = new Parse.Query(comment);

queryPosts.matchesQuery("commentsList", queryComments);

return queryPosts.find().then(function (postsResult) {

console.log('prepareResponses: number of posts found: ' + postsResult.length);

然后,当然,我想得到这样的评论可能吗?

p = postsResult[0].get("commentsList");
console.log("Number of comments in the first post is: " + p.length);

我想查询特定类中的所有行(假设comments是post中的关系对象):

var post = Parse.Object.extend("post");
var postQuery = Parse.Query(post);
postQuery.includeKey("comments");
//post query will return all rows in post class with the comments relation loaded

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM