Search code examples
parse-platformscalabilitypfrelation

Should I use an array of pointers or a PFRelation? (parse.com)


As far as I can tell, the only reason you might use an array of pointers is to preserve ordering, as a PFRelation instance does not support ordering. Otherwise, they appear to behave identically, albeit PFRelation is more scalable and also has a nifty built-in 'query' method to restrict a query just to the objects in the PFRelation instance, which is super helpful sometimes.

PFRelation *relation = ...
PFQuery *query = [relation query];

Context: I am building an app in which each PFUser instance HAS MANY TennisGame instances (could be a large number), and the TennisGame instances HAS MANY PFUser instances (either 2 or 4, depending on whether it was a singles game or a doubles game).

Question: What is the best way to organise my data on parse.com ? I was considering a PFRelation in my PFUser class (to TennisGame instances), as well as an array or 2 or 4 pointers in my TennisGame class (to PFUser instances). But do I need both? If not, which is best?


Solution

  • The question is about how you access your data. For your case, you can think about these questions:

    • Do you need to include a user's TennisGames whenever you get a user? If yes, arrays support include on queries. You can't do include with relations and you need to do one more query to access a user's TennisGames.
    • How many TennisGames will a user have at max? If it is likely to be more than 100 (recommended limit by Parse), it is better you go with relations. Because arrays don't scale to large relationships.
    • As you pointed it out, is the order important for you? If yes, arrays support order.
    • And again as you said, if you are interested a subset of data, relations are able to restrict queries while arrays aren't.

    I suggest you to watch this video about Parse relationships from Parse developer days.

    Moreover, you don't need the keep the relationship in both sides. This would make it more complicated to create and update them.