我有个定制的分析课..。
Follow
-----------------
Follower - PFUser
Followee - PFUser我还向User表添加了一个自定义字段fullName。
这是无法改变的。(虽然可以加进去)
我已经使用它做了几个查询,我在最后一个问题上遇到了绊脚石。
我希望能够运行一个查询,返回fullName包含一些给定文本的用户,但只返回跟踪当前用户的用户。
即
如果Paul和Peter跟在我后面,就会有跟随对象,我是跟随者,他们是跟随者。而且,Phillip没有跟踪我,所以他没有跟踪记录。
如果我使用搜索文本@"P"运行这个查询,那么它应该返回Peter和Paul,而不是Phillip。
我只是想不出如何创建查询。
我试过这样的..。
PFQuery *followQuery = [CCFollow query];
[followQuery whereKey:@"followee" equalTo:[PFUser currentUser]];
PFQuery *nameQuery = [PFUser query];
[nameQuery whereKey:@"fullName" contains:searchText];
[nameQuery whereKey:@"objectId" equalsKey:@"follower" inQuery:followQuery];但它不返回错误,也不返回对象。
发布于 2014-08-12 20:29:28
[nameQuery whereKey:@"objectId" equalsKey:@"follower" inQuery:followQuery];这一行代码不正确。在这里,键objectId是string类型,追随者是PFUser类型。您可以创建一个额外的列"followerString“,它以字符串格式存储追随者的objectId,以便进行比较。
发布于 2014-08-13 09:30:23
更好的选择是将查询切换到:
获取所有Follow记录,其中followee是当前用户,follower包含在与fullName查询匹配的User记录查询中。
PFQuery *followQuery = [CCFollow query];
[followQuery whereKey:@"followee" equalTo:[PFUser currentUser]];
PFQuery *nameQuery = [PFUser query];
[nameQuery whereKey:@"fullName" contains:searchText];
// here's the difference:
[followQuery whereKey:@"follower" matchesQuery:nameQuery];
// include follower
[followQuery includeKey:@"follower"];
// now run find on followQuery (not nameQuery)
[followQuery findObjectsInBackgroundWithBlock:^(NSArray *follows, NSError *error) {
// "follows" now contains the follow records, and the "follower" field
// has been populated. For example:
for (PFObject *follow in follows) {
// This does not require a network access.
PFObject *follower = follow[@"follower"];
NSLog(@"retrieved related user: %@", follower);
// could put them in an array or whatever to bind to the UI
}
}];这样做,您不需要更改模式或开始将objectId引用存储为字符串。
https://stackoverflow.com/questions/25268023
复制相似问题