iOS解析如何从基于两个类的查询中检索对象? [英] IOS Parse how do I retrieving objects from a query based on two classes?

查看:80
本文介绍了iOS解析如何从基于两个类的查询中检索对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个类UserPost. User类有一个userType字段,我想从给定的userType中检索所有帖子,让我们将它们称为组x.在Post类中,我有一个指向User类的指针.

I have two classes User and Post. The User class has a userType field and I want to retrieve all of the posts from a given userType lets call them group x. In the Post class I have a pointer to the User class.

我试图做类似的事情,首先检索我想要的用户类型的所有用户ID:

I was trying to do something like, first retrieve all user Ids for the type of user I want:

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进行查询,但是我不确定如何在此数组上进行查询,或者这是否是执行此操作的正确方法.该怎么办?

And then I wanted to query based on these objectIds but I am not sure how to query on this array or if this is even the correct way to do this. How can this be done?

推荐答案

Parse在查询中提供了matchesQuery方法,因此...

Parse provides a matchesQuery method on query, so ...

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
}];

这篇关于iOS解析如何从基于两个类的查询中检索对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆