使用 Parse.com 进行多查询搜索 [英] Multiple Query Search with Parse.com
问题描述
我正在尝试根据某些凭据查询以查找特定用户.
I'm trying to query to find specific users based on certain credentials.
查询只会在 User 类中查找.
The query will only look in the User class.
首先,我希望查询匹配当前用户的位置
First, I want the query to match the currentUser's location
其次,必须匹配特定的类别(意味着同一位置的多个用户可能属于同一类别)
Second, must match a specific category (meaning multiple users in the same location may be under the same category)
这是我尝试过的:
self.profileObj = [self.currentUser objectForKey:@"city"];
PFQuery * queryOne = [PFUser query];
[queryOne whereKey:@"city" equalTo:self.profileObj];
PFQuery * queryTwo = [PFUser query];
[queryTwo whereKey:@"category" equalTo:self.tagString];
PFQuery * query = [PFQuery orQueryWithSubqueries:@[queryOne, queryTwo]];
[query orderByAscending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:(NSArrayobjects, NSError error)
这将返回 0 个结果.
This is returning 0 results.
推荐答案
您不需要两个单独的查询,因为您正在查询同一个 User 对象.另外,我相信您想要两个 AND 约束而不是 OR?如果是这样,您可以将两个 whereKeys 链接在一起:
You don't need two separate queries since you are querying on the same User object. Also, I believe you want two AND constraints rather than OR? If so, you can just chain together two whereKeys:
PFQuery * query = [PFQuery queryWithClassName:@"User"];
[query whereKey:@"city" equalTo:self.profileObj];
[query whereKey:@"category" equalTo:self.tagString];
[query orderByAscending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
...
}];
这篇关于使用 Parse.com 进行多查询搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!