Juan Carlos HC
Juan Carlos HC

Reputation: 25

Getting PFUser from relational query Parse - iOS - Objective C

I'm trying to get a user from a pointer which is pointing to that user from a different table ( the table is called Parental ) but I can not get the full user only objectId , this is my code:

PFUser *usuario = [PFUser currentUser];

self.listausuarios = [[NSMutableArray alloc] init];

PFQuery *query = [PFQuery queryWithClassName:@"Parental"];
[query includeKey:@"Users"];
[query whereKey:@"supervisado" equalTo:usuario];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    PFObject *parentalCompleto;

    if (!error) {

        NSUInteger contador = 0;

        for (parentalCompleto in objects) {

            PFUser *contacto = [parentalCompleto objectForKey:@"supervisor"];

            NSLog(@"User from query: %@", parentalCompleto[@"supervisor"]);
            NSLog(@"User from query 2: %@", contacto);
            NSLog(@"Current User: %@", usuario);

            [self.listausuarios insertObject:contacto atIndex:contador];

            contador = contador + 1;
        }

        [self.tableView reloadData];
    }
}];

This is the Parse database:

enter image description here

enter image description here

And this is the console output:

enter image description here

Why I can not get user data with " objectId : ZYcjtEEDjt "?

Upvotes: 0

Views: 91

Answers (1)

Frankie
Frankie

Reputation: 11928

From first glance, it might be because you are including the key Users, which is not a column in your table. If you want the full object for supervisor or supervisado then you need to include those keys.

[query includeKey:@"supervisor"];
[query includeKey:@"supervisado"];

Only include the ones you need.

P.S. Reload your tableView on the main thread.

Upvotes: 1

Related Questions