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?

有帮助吗?

解决方案

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

其他提示

You can retrieve the pointer to User field from the Post table by adding this line of code (in Android):

postQuery.include("pointerToUser");

postQuery is query of class Post. By this way, after executing the query the object or objects that will be returned would have the user information.

You can see a full example here: How to query value of column that is set as pointer to other table in Parse

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top