如果我有一个指向数组中多个_User
对象的指针,我可以查询一个User
的值。
例如
我有一个类Groups
和一个数组members
。
members = [user1, user2, user3]
。
我可以做类似的事情吗?
PFQuery *query = [PFQuery queryWithClassName:@"Groups"];
[query whereKey:@"members.name" isEqual:@"James"];
答案 0 :(得分:0)
这可以通过嵌套查询来完成。创建一个“ innerQuery”以查找符合条件的用户。然后用Group
约束whereKey:matchesQuery:
查询。
PFQuery *innerQuery = [PFUser query];
// note that referring to the "name" field only makes sense if you've
// added a name field to User (you might mean username here)...
[innerQuery whereKey:@"name" isEqual:@"James"];
// now the main query is setup to match the innerQuery
PFQuery *query = [PFQuery queryWithClassName:@"Groups"];
[query whereKey:@"members" matchesQuery:innerQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
}];