Search code examples
iosparse-platformrelationpfquerypfrelation

Start query from relation


I have a class named Circle with a relation named "members" to the _User class.

Class Circle:

Data of class Circle

Class _User:

Data of class _User

I'm trying to query all Circles that the current user belongs to (inside the "members" relations).

PFUser *user = [PFUser currentUser];
PFRelation *relation = [user relationForKey:@"members"];

PFQuery *query = [relation query];

[query findObjectsInBackgroundWithBlock:^(NSArray *PF_NULLABLE_S objects, NSError *PF_NULLABLE_S error){
    //objects size here is 0
    //error is nil
}];

The problem is that the NSArray is empty and no error is received into the block.

One solution I'm thinking of is creating an actual table to store this relation and have a Relation column in both Circle and _User, but I believe there should be a better way to do this.


Solution

  • It doesn't appear that user has a members col. So, asking a user for its members relation is sure to fail. You want to query Circle...

    PFQuery *query = [PFQuery queryWithClassName:@"Circle"];
    [query whereKey:@"members" equalTo:user];