简体   繁体   English

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

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

I have the following relation in my Parse schema: "Post" items with "Comments" child items. 我的Parse模式中有以下关系:“Post”项目带有“Comments”子项。 I'm Using Arrays for One-to-Many Relations as described here: relations_guide 我正在使用Arrays for One-to-Many Relations,如下所述: relations_guide

How can i fetch all Posts (even those with no comments) with all the comments for each post? 如何获取所有帖子(即使没有评论的帖子)以及每篇帖子的所有评论?

I was trying something like this: 我正在尝试这样的事情:

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);

and then, of course, I would like to get the comments out of the post like this maybe? 然后,当然,我想得到这样的评论可能吗?

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

I you want to query for all rows in a particular class (assuming comments is a relations object in post): 我想查询特定类中的所有行(假设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