PFRelation objects or query with key?

823 views Asked by At

I am building a simple app that allows a user to login and a tableview displays the friend list.

I initially thought I would include a friends array in the PFUser class containing the ID's of the people the user is friends with. So when the app loads, the table would populate by returning the PFUser objects for those IDs using:

PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query whereKey:@"id" equalTo:@"someID"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) etc..

Would it be better to create a PFRelation field and find the users from this instead on searching by the user ID? Not sure which one is faster and more efficient. Hope someone can help

Thank you

1

There are 1 answers

2
Ryan Kreager On BEST ANSWER

I would recommend a PFRelation field. From the Parse documentation:

This works similar to an NSArray of PFObjects, except that you don't need to download all the Objects in a relation at once. This allows PFRelation to scale to many more objects than the NSArray of PFObject approach.

In other words, the PFRelation makes more sense as you scale, especially if you conceive of individuals having lists of 100s or 1000s of friends. PFRelation is flexible and allows you to more easily query for only the friends you are seeking at the moment; for example, if you wanted to find only friends who had logged in during the past 24 hours.

Learn more here: https://www.parse.com/docs/ios_guide#objects-pointers/iOS