In the parse.com
framework
you can associate an object with another object with a PFRelation
. I was reading the Parse docs on this but I'm not finding a key point in the documentation. What exactly is the advantage of using a PFRelation
? Like, does it make querying for thing faster or more efficient? Does it make it easy for the parse database to keep track of things?
Someone help me out with understanding this.
Asked
Active
Viewed 323 times
1

Anbu.Karthik
- 82,064
- 23
- 174
- 143

Brandon A
- 8,153
- 3
- 42
- 77
1 Answers
1
It makes the maintenance and usage of to-many relationships easy because you can add and remove individual relationships to the set and query the contents of the set. With other relationship approaches (like pointers) this is generally harder to do. It's hard to say about efficiency as that isn't documented but relationships are documented to be the preferred approach so we can assume that they are more efficient.

Wain
- 118,658
- 15
- 128
- 151
-
Hello Wain. Thank you for your answer. So let me see if I understand you correctly. If I have a PFQueryTableViewController and I have a post a user has posted - can I set a PFRelation to the post and the user for the purposes of generating a query (1 time - efficiency) to be able to populate my PFQueryTableViewController with not only the post but the user's profile picture for example? The benefits of it might be that we only generate 1 request for both the post and user. Is this right? – Brandon A Dec 01 '14 at 08:19
-
A relationship is a persistent connection between two (multiple) instances in the data store, so you wouldn't just create a relationship to be able to query - you create the relationship to describe and store the connection information and then you query the relationship later to use that info. – Wain Dec 01 '14 at 10:56
-
I would recommend using arrays of pointers when the relationship is one to many, but the numbers are limited. PFRelation is overkill and a PITA if you only expect 5 or 10 entries. The key advantage of an array of pointers is that you can use includeKey with it. I would use an array up to say 100 entries, but I think it will still work up to several hundred. Beyond that you will run into the 1000 object query limit. – LostInTheTrees Dec 01 '14 at 17:25
-
Thank you LostInTheTrees. So you believe the best solution is to use my PFQueryTableViewController to get the posts (1 query) and inside my cellForRowAtIndexPath do another query for the user's picture (1 query). And doing it this way with two queries is the best and most efficient way I can accomplish this? Also what do you mean by an array of pointers? – Brandon A Dec 02 '14 at 01:10
-
@BillyA In cases where the number of related objects is smallish, instead of creating a field that is a PFRelation, create an array. Add the related objects to that array. Then when you do a query, you can say includeKey: @"arrayname". The qury will then bring in all the related objects along with the master object. I certainly would never do a query in cellForRowAtIndexPath. – LostInTheTrees Dec 02 '14 at 21:15