如何使用 Parse.Query 检索一对多关系
解析文档解释了如何在查询子对象时检索父对象:
const query = new Parse.Query(Comment);
// Include the post data with each comment
query.include("post");
const comments = await query.find();
但它并没有提到另一个方向(在我看来是自然方向):我想查询帖子,并且我希望每个帖子都包含其评论数组。有办法做到这一点吗?
The parse documentation explains how to retrieve a parent object when querying for children:
const query = new Parse.Query(Comment);
// Include the post data with each comment
query.include("post");
const comments = await query.find();
But it says nothing about going in the other direction (the natural direction, it seems to me): I want to query for posts, and I want each post to include its array of comments. Is there a way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您使用 aggregate。
如果不使用聚合,您将必须执行两个查询:
You can't retrieve one post and all related comments in a single query unless you use aggregate.
Without using aggregate, you will have to perform two queries: