简体   繁体   English

查询解析以获取对象的状态

[英]Query Parse to get state of object

I am developing a social application using parse. 我正在使用解析开发社交应用程序。 I have following data models for parse.com 我为parse.com使用以下数据模型

User 用户

  • name (String) 名称(字符串)
  • email (String) 电子邮件(字符串)
  • ... ...

Post 发布

  • tittle (String) 标题(字符串)
  • description (String) 说明(字符串)
  • User (Pointer) 用户(指针)
  • Like (Pointer) 喜欢(指针)
  • Comment (Pointer) 评论(指针)
  • LikeCount (Number) LikeCount(数字)
  • Comment Count (Number) 评论数(数字)

Like 喜欢

  • User (Pointer) 用户(指针)
  • Post (Pointer) 发布(指针)

Comments 评论

  • text (String) 文字(字串)
  • User (Pointer) 用户(指针)
  • Post (Pointer) 发布(指针)

Now when I fetch posts I also want to fetch additional information which is 现在,当我获取帖子时,我也想获取其他信息,这是

  1. If current user liked this post? 当前用户是否喜欢此帖子?
  2. If current user commented on this post? 如果当前用户对此帖子发表了评论?

I am wondering If I can get all these info in one network call. 我想知道是否可以在一个网络呼叫中获得所有这些信息。 I don't want to perform multiple network calls for each post. 我不想为每个帖子执行多个网络通话。

In your query for fetching the post, you can indicate that you want the query to return also the related objects, like this: 在获取帖子的查询中,可以指示您希望查询还返回相关对象,如下所示:

...
query.include("User");
query.include("Like");
query.include("Comment");

or even 甚至

query.include("Like.User");

to get the Like object AND the User object related to that Like object 获取Like对象和与该Like对象相关的User对象

This will ensure that you get the full objects; 这将确保您获得完整的对象; not just the pointers to them. 不只是指向它们的指针。

However, these queries quickly become complex. 但是,这些查询很快变得复杂。 I recommend you read the Parse tutorial for the Anypic app, and see how they have solved this. 我建议您阅读Anypic应用程序的Parse教程,并查看他们如何解决此问题的。 Anypic is for iOS only, but you should be able to understand the concepts. Anypic仅适用于iOS,但您应该能够理解这些概念。 https://parse.com/tutorials/anypic https://parse.com/tutorials/anypic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM