ios - 如何使用解析添加两个PFquery数据的对象?

标签 ios parse-platform pfquery

我有两个查询,一个是friendsrequestQuery,另一个是用户查询,我想在从用户查询中获取数据时,将friendrequestQuery详细信息的所有数据添加到用户查询中。

NSPredicate *predicate12=[NSPredicate predicateWithFormat:@"((UserFriendId == %@ )AND (UserId!=%@)) OR ((UserFriendId != %@ )AND (UserId==%@)) ",@"Nwk44aeSrz",@"Nwk44aeSrz",@"Nwk44aeSrz",@"Nwk44aeSrz"];
PFQuery *innerQuery = [PFQuery queryWithClassName:@"FriendsDetails" predicate:predicate12];
[innerQuery whereKey:@"BlockStatus" equalTo:@"No"];
PFQuery * userQuery = [PFUser query];

[userQuery whereKey:@"objectId" matchesKey:@"UserFriendId" inQuery:innerQuery];
[userQuery whereKey:@"objectId" matchesKey:@"UserId" inQuery:innerQuery];

[userQuery whereKey:@"objectId" notEqualTo:@"Nwk44aeSrz"];

我将解释我到底需要什么,在innerquery表中,我有10列,但在恢复用户查询的数据时,我需要这些特定的coloum数据转换的数据,lastmessage,lastdate。
现在我得到的是userquery的详细信息,而不是innerquery的详细信息,所以我需要Innerquerydetails的详细信息。
请帮我 。

最佳答案

我认为最好存储指针而不是存储ID,这样您也可以包含该数据。

我不会使用谓词,我知道您的查询使用谓词会更干净,但是我认为使用此逻辑更容易理解。您可以将其转换回自己的谓词。

// get your user
PFUser * userForQuery; // set up your user for the query, if it's current user, = [PFUser currentUser];

// first part of predicate
PFQuery * innerQueryA = [PFQuery queryWithClassName:@"FriendsDetails"];
[innerQueryA whereKey:@"UserFriend" equalTo:userForQuery]; // from  @"UserFriendId"
[innerQueryA whereKey:@"User" notEqualTo:userForQuery]; // from @"UserId"

// second part of predicate
PFQuery * innerQueryB = [PFQuery queryWithClassName:@"FriendsDetails"];
[innerQueryB whereKey:@"userFriend" notEqualTo:userForQuery]; // from @"UserFriendId"
[innerQueryB whereKey:@"user" equalTo:userForQuery]; // from @"UserId"

// combine
PFQuery * query = [PFQuery orQueryWithSubqueries:@[innerQueryA, innerQueryB]];
[query whereKey:@"BlockStatus" equalTo:@"No"];

// Now, as you remember, we are storing a pointer in @"User" as opposed to an id @"UserId" as you had it. Because of     
// this, we will use parse's includeKey: feature.

[query includeKey:@"User"]; // tells the query to include the data associated with these keys;

NSMutableArray * usersRetrieved = [[NSMutableArray alloc]init];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {    
        // objects will contain all of your objects
        for (PFObject * object in objects) {
            [usersRetrieved addObject:object[@"User"]]; // all the data should be available for the @"User" object
        }

        // objects will contain all the @"friendDetails" objects
        // usersRetrieved will contain all the @"User" objects
    }
    else {
    }
}];

我意识到这会稍微改变您的数据结构,但它应该为您提供所需的所有数据。

关于ios - 如何使用解析添加两个PFquery数据的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17500097/

相关文章:

ios - 重定向到第一个 ViewController

ios - viewdidappear 未从选项卡栏 Controller 调用

ios - 如何重新解析 tableView 中的 xml 数据?

javascript - Parse.com 代码不会部署 : "Could not load triggers"

ios - 尝试在 Parse 中查询对象

iOS (Swift) - 应用程序委托(delegate)窗口的 Root View Controller 在模拟器中工作,但在手机上加载应用程序时失败

swift - print 在 Swift 3 扩展中不起作用

xcode - 解析 SDK 1.7.1 在 Xcode 6.3 中不起作用

ios - 如何在 Root View Controller (PFQueryTableViewController)尝试没有用户的查询并使程序崩溃之前显示登录屏幕

ios - 如何查询类并检查键是否为空或值