如何使用Parse.Query检索一对多关系



解析文档解释了在查询子对象时如何检索父对象:

const query = new Parse.Query(Comment);
// Include the post data with each comment
query.include("post");
const comments = await query.find();

但它并没有说要朝另一个方向发展(在我看来,这是自然的方向(:我想查询帖子,我希望每条帖子都包含它的一系列评论。有办法做到这一点吗?

除非使用聚合,否则无法在单个查询中检索一篇文章和所有相关评论。

如果不使用聚合,您将不得不执行两个查询:

const post = await (new Parse.Query(Post)).get(postId);
const comments = await (new Parse.Query(Comment)).equalTo('post', post).find();

最新更新