0

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.

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?

-(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];
        }
    }];



}
10
  • It's Italian, so it's very difficult for me to understand your database schemes. You should give us more details about your database scheme :) Commented Nov 2, 2013 at 8:22
  • Can you try to add this [QueryForFriend includeKey:@"Da_User"] under your QueryForFriend queries. This might be problem if Da_User is a pointer Commented Nov 2, 2013 at 8:26
  • BabyGau Hello and thank you for your answer: D I edited the post trying to put all the letters of the database in English to make you understand better ... I also tried to add your advice (includekey Da_User) but it did not work ... the time the user current posts do not appear ... : (((( Commented Nov 2, 2013 at 12:59
  • I don't think there is anything wrong with your query. I put my doubt on this line [query orderByDescending:FF_CREATEDAT]; where FF_CREATEDAT might be not match with key createdAt in POST class. Is ArrayforPost a datasource of FFTableView??? Commented Nov 2, 2013 at 13:21
  • It ArrayforPost is' NSMutableArray used in Tableview .... My whole problem goes away if I remove this line [QueryForFriend whereKey: @ "To_User" equalTo: [PFUser currentUser]]; So I view the post also the time the user Current the problem is that if I remove this line the current user sees the post of all subscribers to the app and this is not good because it should only read the posts of his friends as in normal social network ... Adding this line posts are filtered and displayed only a friend's post but it seems that the posts do not appear CurrentUser Commented Nov 2, 2013 at 13:34

1 Answer 1

4

After a long discussion with @rory, here we come to the correct answer:

-(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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks again for everything you're always very helpful and kind!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.