0

大家好,我发布的查询中的每个人都在尝试检索与 PfUserCurrent 有友谊的人的所有帖子和 PfUserCurrent 的所有帖子。

查询工作正常,但我只有一个问题,查询显示了 CurrentUser 之友的所有帖子,但没有显示 CurrentUser 发送的帖子...我尝试了几次但我无法解决这个问题.. . 你能解释我哪里错了吗?

-(void)QueryForPost {

    PFQuery *QueryForFriend=[PFQuery queryWithClassName:@"Friendships"];
    [QueryForFriend whereKey:@"To_User" equalTo:[PFUser currentUser]];
    [QueryForFriend whereKey:@"STATUS"  equalTo:@"Confirmed"];



    PFQuery *QueryYES = [PFQuery queryWithClassName:@"Post"];
    [QueryYES whereKey:@"FLASH_POST" equalTo:[NSNumber numberWithBool:YES]];
    [QueryYES whereKey:@"UserSelected" equalTo:[PFUser currentUser]];


    PFQuery *QueryNO = [PFQuery queryWithClassName:@"Post"];
    [QueryNO whereKey:@"FLASH_POST" equalTo:[NSNumber numberWithBool:NO]];
    [QueryNO whereKey:@"Author" matchesKey:@"From_User" inQuery:QueryForFriend];

    PFQuery *query = [PFQuery orQueryWithSubqueries:@[QueryYES,QueryNO]];
    [query includeKey:@"Author"];

    [query orderByDescending:FF_CREATEDAT];
    [query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
        if (!error) {
            NSLog(@"%@", results);
            ArrayforPost = [[NSMutableArray alloc] init];
            for (PFObject *object in results) {
                [ArrayforPost addObject:object];
            }
            [self.FFTableView reloadData];
        }
    }];



}
4

1 回答 1

4

经过与@rory 的长时间讨论,我们得出了正确答案:

-(void)QueryForPost {

PFQuery *QueryForFriend=[PFQuery queryWithClassName:@"Amicizie"]; 
[QueryForFriend whereKey:@"A_User" equalTo:[PFUser currentUser]]; 
[QueryForFriend whereKey:@"STATO" equalTo:@"Confermato"]; 
[QueryForFriend includeKey:@"Da_User"]; 

PFQuery *QueryYES = [PFQuery queryWithClassName:@"Post"]; 
[QueryYES whereKey:@"FLASH_POST" equalTo:[NSNumber numberWithBool:YES]]; 
[QueryYES whereKey:@"Scelti" equalTo:[PFUser currentUser]]; 

PFQuery *normalPostByFriends = [PFQuery queryWithClassName: @"Post"]; 
[normalPostByFriends whereKey: @"FLASH_POST" equalTo: [NSNumber numberWithBool: NO]]; 
[normalPostByFriends whereKey: @"Utente" matchesKey:@"Da_User" inQuery:QueryForFriend]; 

PFQuery *normalPostByUser = [PFQuery queryWithClassName:@"Post"]; 
[normalPostByUser whereKey: @"FLASH_POST" equalTo: [NSNumber numberWithBool: NO]]; 
[normalPostByUser whereKey: @"Utente" equalTo: [PFUser currentUser]];

PFQuery *query = [PFQuery orQueryWithSubqueries:@[QueryYES,normalPostByFriends,normalPostByUser  ]];
[query includeKey:@"Author"];

[query orderByDescending:FF_CREATEDAT];
[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
    if (!error) {
        NSLog(@"%@", results);
        ArrayforPost = [[NSMutableArray alloc] init];
        for (PFObject *object in results) {
            [ArrayforPost addObject:object];
        }
        [self.FFTableView reloadData];
    }
}];

}

通过进行另一个查询以显示当前用户的正常帖子并修改QueryForFriend以获取正确的查询来处理该问题

于 2013-11-03T03:00:38.750 回答