我有两个表TrendingUsersFollow。所需功能类似于从TrendingUsers表中获取用户并愿意关注,前提是获取的用户不在用户关注列表中。如果用户已经被关注,则跳过。

Follow表具有列followerleader

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)
{
    //...
}];


我可能还没有完全理解您的数据结构,因此您可能必须交换上述代码中的一个或多个键,但是基本上,这就是您要执行的操作。

09-07 11:20