【问题标题】:Parse - get parent items with their child items in array one to many relationParse - 在数组中获取父项及其子项的一对多关系
【发布时间】:2015-04-19 05:57:56
【问题描述】:

我的 Parse 架构中有以下关系: 带有“评论”子项目的“发布”项目。我正在将数组用于一对多关系,如下所述:relations_guide

如何获取所有帖子(即使是没有 cmets 的帖子)以及每个帖子的所有 cmets?

我正在尝试这样的事情:

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

然后,当然,我想让 cmets 退出帖子 大概是这样?

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

【问题讨论】:

  • 您是要查找所有帖子、所有带有特定 cmets 的帖子,还是所有 cmets?不清楚你想要什么
  • 尝试查找所有帖子,即使是那些 cmets 为零的帖子)以及每个帖子的所有 cmets。

标签: javascript parse-platform one-to-many relation


【解决方案1】:

我想查询特定类中的所有行(假设 cmets 是 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 2016-07-20
    • 2012-12-21
    • 1970-01-01
    相关资源
    最近更新 更多