如何获得多个查询的结果?

时间:2019-05-02 09:32:41

标签: android parse-platform parse-server

我正在做一个社交媒体应用。当我关注人们时,我将“关注对象”保存到服务器,如下所示:

ParseObject follow = new ParseObject("Follow");                       
followquery.put("owner",ParseUser.getCurrentUser());
followquery.put("who",otherUser);

但是我想获得追随者的职位。像这样:

ParseQuery followingsQuery = new ParseQuery("Follow");
//get people i follow
followings.whereEqualTo("owner",ParseUser.getCurrentUser());

ParseQuery getpost = new ParseQuery("Post");
//get posts that shared by a person that i follow
getpost.whereEqualTo("user",followingsQuery);
getpost.findInBackground(new FindCallback() {
    @Override
    public void done(List objects, ParseException e) {

    }

    @Override
    public void done(Object o, Throwable throwable) {

    }
});

我想要这样的东西如何实现?

1 个答案:

答案 0 :(得分:0)

看起来像您想要的whereMatchesQuery。在您的情况下使用以下情况,您的内部查询将成为您的关注者,而您的查询将是帖子。

https://docs.parseplatform.org/android/guide/#relational-queries

从文档中提取

  

如果要检索字段包含ParseObject的对象   与其他查询匹配的内容,可以使用whereMatchesQuery。在   为了找到包含图像的帖子的评论,您可以执行以下操作:

ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("Post");
innerQuery.whereExists("image");
ParseQuery<ParseObject> query = ParseQuery.getQuery("Comment");
query.whereMatchesQuery("post", innerQuery);
query.findInBackground(new FindCallback<ParseObject>() {
  public void done(List<ParseObject> commentList, ParseException e) {
    // comments now contains the comments for posts with images.
  }
});