简体   繁体   English

Parse.com查询PFUser CurrentUser

[英]Parse.com Query for PFUser CurrentUser

Hello to everyone in the query I posted I'm trying to retrieve all of the posts and PfUserCurrent all posts of people who have shared a friendship with PfUserCurrent. 在我发布的查询中向大家问好,我试图检索所有与PfUserCurrent共享友谊的人的帖子和PfUserCurrent。

The query works fine but I have only one problem, the query shows me all the posts of Friends of the CurrentUser but does not show me those sent by the CurrentUser ... I've tried several attempts but I could not fix this ... Can you explain where I'm wrong? 该查询工作正常,但我只有一个问题,该查询显示了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];
        }
    }];



}

After a long discussion with @rory, here we come to the correct answer: 经过与@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];
    }
}];

}

The problem is handled by making another query to display current user's normal post and modify QueryForFriend for a correct query 通过进行另一个查询以显示当前用户的正常帖子并修改QueryForFriend以获取正确的查询来解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM