user3926776
user3926776

Reputation:

Parse query retrieve pointer columns

I have a Filter class which has a pointer to a user in my User class. I'm wondering how can I get the Filter object in the Filter class which is equal to the [PFUser CurrentUser] and then get both column values from the User and Filter class

PFQuery *filterQuery = [PFQuery queryWithClassName:@"Filter"];
filterQuery.limit = 1;
[filterQuery whereKey:@"userId" equalTo:[PFUser currentUser].objectId];
[filterQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
     if(!error){                                
         NSLog(@"%@", objects);                                                                                                         
     }                                                     
}];

Upvotes: 1

Views: 928

Answers (1)

Fogmeister
Fogmeister

Reputation: 77661

You just use the object itself...

PFQuery *filterQuery = [PFQuery queryWithClassName:@"Filter"];
filterQuery.limit = 1;
[filterQuery whereKey:@"userId" equalTo:[PFUser currentUser]]; //no need to put objected here.
[filterQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
     if(!error){                                
         NSLog(@"%@", objects);                                                                                                         
     }                                                     
}];

As long as the userId field is a pointer to the _User object then this will work.

If userId is a pointer to _User then you can add...

[filterQuery includeKey:@"userId"];

This will then populate the userId object of the Filter objects with data when they are sent down. If you don't put that line then you will just get the objectId in the userId object.

However, I'm not sure you've done it as a Pointer. Can you confirm that it definitely is.

You should have this in the Data Browser table for Filter...

enter image description here

(follower will say userId on yours)

Upvotes: 1

Related Questions