How to store likes to posts in Parse.com database

database-designparse

In my parse database I have a classed called Post and Like. Should I create a field likes in Post class with Relation<Like> type or there is another better option of storing likes in Parse DB?

Best Answer

For those purpose, I only use relations in the USER table with users ids stored as pointers inside.

Using a cloud code function, I provide a parameter to add , del or whatever instructions to apply to a single or an array of users. Cloud gives the opportunity to create collateral events such as "a user like this"

As a reading step, a query is applied to the relation to retrieve parts or all users.

The column is named with the purpose such as I will add 2 columns to mention respectively "like" , "dontLike"

However, if one need more than a single information , a second table needs to be created and linked also with a relation. For example, a new table with a first column which is a regular pointer to users, other columns to stored the additional attributes. Which means that this new table must be first saved, to be able to stored its id in the relation.