问题
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?
回答1:
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);
}
}
回答2:
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
来源:https://stackoverflow.com/questions/19099137/query-with-pointer-user-in-parse-com