问题
I am trying to write a Parse query for my iOS social app that will show all users that are following the active user. Here is what I have so far:
PFQuery *followingUser = [PFQuery queryWithClassName:@"Activity"];
[followingUser whereKey:@"Activity" equalTo:@"follow"];
[followingUser whereKey:@"fromUser" equalTo:self.user];
[followingUser includeKey:@"User"];
[followingUser setCachePolicy:kPFCachePolicyCacheThenNetwork];
Currently this correctly gives me all the records of the active user following any other users, But this doesn't give me the PFUser details (user profile pic, display name, etc) for the corresponding records. Any ideas on how i can easily draw out the PFUser details in the one query?
Thanks in advance
回答1:
Here is some sample code of a query that I used to get all the users being followed, all posts from the users being followed, and all posts from the current user. I hope this helps!
// List of all users being followed by current user
PFQuery *followingActivitiesQuery = [PFQuery queryWithClassName:kFTActivityClassKey];
[followingActivitiesQuery whereKey:kFTActivityTypeKey equalTo:kFTActivityTypeFollow];
[followingActivitiesQuery whereKey:kFTActivityFromUserKey equalTo:[PFUser currentUser]];
followingActivitiesQuery.cachePolicy = kPFCachePolicyNetworkOnly;
followingActivitiesQuery.limit = 100;
// Posts from users being followed
PFQuery *postsFromFollowedUsersQuery = [PFQuery queryWithClassName:self.parseClassName];
[postsFromFollowedUsersQuery whereKey:kFTPostUserKey matchesKey:kFTActivityToUserKey inQuery:followingActivitiesQuery];
[postsFromFollowedUsersQuery whereKey:kFTPostTypeKey containedIn:@[kFTPostTypeImage,kFTPostTypeVideo,kFTPostTypeGallery]];
// Posts from current user
PFQuery *postsFromCurrentUserQuery = [PFQuery queryWithClassName:self.parseClassName];
[postsFromCurrentUserQuery whereKey:kFTPostUserKey equalTo:[PFUser currentUser]];
[postsFromCurrentUserQuery whereKey:kFTPostTypeKey containedIn:@[kFTPostTypeImage,kFTPostTypeVideo,kFTPostTypeGallery]];
PFQuery *query = [PFQuery orQueryWithSubqueries:[NSArray arrayWithObjects: postsFromFollowedUsersQuery, postsFromCurrentUserQuery, nil]];
[query includeKey:kFTPostUserKey];
[query orderByDescending:@"createdAt"];
来源:https://stackoverflow.com/questions/26150007/parse-ios-how-to-query-pfuser-details-from-another-class