我正在使用 Parse 构建一个 iOS 应用程序,该应用程序有一些复杂的查询,并且在使用 PFRelation 时遇到了一些问题。
这是一个人们提交文章的社交网络网站。您可以关注其他用户并查看他们提交的文章。您还可以根据主题进行搜索。
这是我的代码
PFQuery* query = [PFQuery queryWithClassName:@"Article"];
//remove articles this user has seen or submitted
[query whereKey:@"likedBy" notEqualTo:currentUser]; //'likedBy' is a relation
[query whereKey:@"dislikedBy" notEqualTo:currentUser]; //'dislikedBy' is a relation
[query whereKey:@"submittedBy" notEqualTo:currentUser]; //'submittedBy' is a relation
[query whereKey:@"tagArray" containedIn:tags];
[query orderByDescending:@"createdAt"];
PFRelation* relation = [currentUser relationForKey:@"following"]; //following is a relation for the user
PFQuery* followingQuery = [relation query];
[followingQuery findObjectsInBackgroundWithBlock:^(NSArray* results, NSError* error) {
//results from this first query is the list of people the user is following
[query whereKey:@"submittedBy" containedIn:results]; //submitted by is a relation on the article
[query findObjectsInBackgroundWithBlock:^(NSArray* results, NSError* error) {
/* This will return all the items that match the tags set above.
However, if there are no tags, I do not get the articles
that match the "submittedBy" above. It is empty */
completion(results);
}];
}];
}
感谢您花时间阅读本文。