1

我有两个班级UserPost. 该类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]];
                }
            }
}];

然后我想根据这些 objectId 进行查询,但我不确定如何查询这个数组,或者这是否是正确的方法。如何才能做到这一点?

4

1 回答 1

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
}];
于 2014-11-02T18:49:24.447 回答