3

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?

2 Answers 2

5

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);
         }
 }
Sign up to request clarification or add additional context in comments.

1 Comment

I'll delete this comment soon, but could you help me here?stackoverflow.com/questions/33606788/…
4

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

3 Comments

@VladIoffe - do you have an answer for doing the same in javascript?
@Akshat Agarwal I think it is the same. Try to write your question and I will try to help.
@vlio20 can u tell me i m facing isue in android how to save ppointer of User table in installation table using parse.com in android in installation table there is this snapshot imgur.com/lShguu5 a pointer of User table i.e objectiD OF user where as object id of user i m getting at the time of sign up of user see this imgur.com/6P7ggQs now i m failed to save pointer user in installation table imgur.com/6P7ggQs imgur.com/lShguu5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.