Search code examples
parse-platformrelationshipdatabasenosql

1 to many relationship in parse


Let's say I have a class Message and a class Conversation on my Parse DB. Conversation are composed by users and by Messages, so if I'll have a huge amount of users and everyone of them will have 2 Conversations with 50 Messages, I'll definitely have a very huge amount of Messages.

My point is that: it is safe to link Messages in Conversations putting a Conversation Pointer in every message, assuming that large amount of Messages (for example: 1.000.000.000 messages)? It is the more efficient way to do this or it can occur performance issues?


Solution

  • A pointer from a message back to its conversation is not expensive. It is only a string the size of an objectID. The better question is how to link a conversation to its messages.

    As I see it, you have 3 choices. You can include an array of object pointers in the conversation. I would eliminate that on the basis that a conversation could be expected to occasionally be large, a few hundred or even over a 1000 messages. IMHO that is too large for an array.

    Second, you can put a PFRelation in the Conversation object and keep track of the messages in that. A PFRelation has unlimited capacity for all intents and purposes.

    Third, you can put a pointer in the Message object back to the Conversation. Then use Query to gather the Message objects for the Conversation.

    Take your pick of the last two.