[英]iOS- parse framework nested query
我有兩個表格TrendingUsers
和Follow
。 所需的功能就像從TrendingUsers
表中獲取用戶並願意關注,前提是獲取的用戶不在用戶關注列表中。 如果用戶已經被關注,則跳過。
Follow
表具有follower
和leader
列。
PFQuery *followTableQuery = [PFQuery queryWithClassName:@"Follow"];
[followTableQuery whereKey:@"follower" equalTo:[PFUser currentUser] ];
[followTableQuery whereKey:@"leader" equalTo:@"fetchedUserObject" ];
[followTableQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
if (objects.count) {
//if following objects array will have single object
}
else
{
//not following to @"fetchedUserObject" user
}
}
}
];
這將確認我currentUser
是否關注@"fetchedUserObject"
用戶。 現在,我要將其集成到TrendingUsers
表查詢中,以僅獲取currentUser
未關注的用戶。
您可以簡單地使用嵌套查詢,Parse的文檔通常是一個很好的起點。 這是一個示例代碼,據我對您的問題的理解,這應該可以解決問題。
//This is our current user
PFUser *user = [PFUser currentUser];
//The first query, querying for all the follow objects from the current user
PFQuery *followingQuery = [PFQuery queryWithClassName:@"Follow"];
[followingQuery whereKey:@"follower" equalTo:user];
//Now we query for the actual trending users, but we do not want the query to return the users (who are in the @"leader" key) that have been found by the first query
PFQuery *trendingQuery = [PFQuery queryWithClassName:@"TrendingUsers"];
[trendingQuery whereKey:@"objectId" notEqualTo:user.objectId]; //don't return the current user
[trendingQuery whereKey:@"objectId" doesNotMatchKey:@"leader" inQuery:followingQuery]; //I'm supposing that @"leader" is containing the objectId of the specific user that is part of the follow object with the current user
[trendingQuery setLimit:1000];
[trendingQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
//...
}];
我可能還沒有完全理解您的數據結構,因此您可能不得不交換上述代碼中的一個或多個鍵,但是基本上,這就是您要執行的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.