在Parse.com中使用指针用户进行查询 [英] Query with pointer User in Parse.com

查看:51
本文介绍了在Parse.com中使用指针用户进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用Parse.com,我创建了一个"Post"类,内部有一个指针,用于指定发送该帖子的用户.现在,我在发布的时间轴上以及创建发布的用户名上看到了时间.由于用户是指针,因此我无法正确查询,您知道如何解决此问题吗?

I am using Parse.com in my app, I have created a "Post" class and inside I have a pointer that specifies which user sent the post. Now I seeing on the timeline to the Post and the time the user name who created the post. Since the user is a pointer I can not make a correct query, do you know how can I fix this issue?

推荐答案

诀窍是使用PFQuery includeKey使相关指针数据由Parse自动填充. user数据将被下载,而无需您再次查询.

The trick is to use PFQuery includeKey to have the related pointer data automatically filled by Parse. The user data will be downloaded without requiring you to make another query for it.

PFQuery *query = [PFQuery queryWithClassName:@"Post"];

// Include the user data with each post
[query includeKey:@"title_of_userpointer_column"];

[query findObjectsInBackgroundWithBlock:^(NSArray *postObjects, NSError *error)
 {
     if (!error) {
         NSLog(@"Successfully retrieved: %d items", [postObjects count]);

         // postObjects now contains the latest 100 Posts, and the "title_of_userpointer_column" field
         // has been populated.
         // For example:
         for (PFObject * postObject in postObjects) {

             // This does not require a network access.
             PFObject *postAuthor = [postObject objectForKey:@"title_of_userpointer_column"];
             NSLog(@"retrieved related Post Author: %@", postAuthor);
         }
 }

这篇关于在Parse.com中使用指针用户进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆