我有两个班级User
和Post
。 User
类有一个userType
字段,我想从给定的userType
中检索所有帖子,然后将其称为组x。在Post
类中,我有一个指向User
类的指针。
我试图做类似的事情,首先检索我想要的用户类型的所有用户ID:
PFQuery *queryUser = [PFQuery queryWithClassName:kFTUserClassKey];
[queryUser whereKey:kFTUserTypeKey equalTo:kFTUserTypeX];
[queryUser whereKey:kFTUserLocationKey nearGeoPoint:nearGeoPoint withinMiles:miles];
[queryUser findObjectsInBackgroundWithBlock:^(NSArray *usersTypeX, NSError *error) {
if (!error) {
NSMutableArray *objectIds = [[NSMutableArray alloc] init];
// Add ambassador ids into query
for (PFObject *userX in usersTypeX) {
[objectIds addObject:[PFObject objectWithoutDataWithClassName:kFTUserClassName objectId: userX.objectId]];
}
}
}];
然后我想基于这些objectIds进行查询,但我不确定如何查询此数组或者这是否是正确的方法。怎么办呢?
答案 0 :(得分:3)
Parse在查询时提供matchesQuery
方法,所以......
PFQuery *innerQuery = [PFQuery queryWithClassName:@"User"];
[innerQuery whereKey:@"userType" equalTo:@"X"]; // fix with your real user type
PFQuery *query = [PFQuery queryWithClassName:@"Post"];
[query whereKey:@"user" matchesQuery:innerQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray *posts, NSError *error) {
// posts are posts where post.user.userType == X
}];