I have a question about the scalability of getting the many from a one-to-many relationship in parse.com. Below is a diagram of what I am trying to do.
I have a Like
object that has a userWhoLiked
and a messageLiked
attributes as pointers. My question is in regards to checking if a User
has liked a message already when loading a feed of Message
objects. I was thinking that I could write some cloud code
that would return both the Message
itself as well as information about if the User
has already liked that object. However, I feel like this would be very inefficient. I would in essence have a query for all the Message
objects (which will be n objects long), and then another query for finding if the User
has already liked that Message
object by going through all the Like
objects n times and checking the userWhoLiked
and messageLiked
based on the user logged in and Message
I am checking. I am going to use the pointer to build the one-to-many relationship because the number of Like
objects will be arbitrarily large. Is the method that I have described (using cloud code
and then checking the Like
objects ) for getting if a user has liked an object is okay and scalable? Is there a better way, or any suggestions? I appreciate your time. Thanks.
Why not just do one query on Like
objects where the userWhoLiked
key is equal to the current user? This will return all of the objects which the current user has liked and you can also infer that all objects not included have not been liked.
In case you haven't checked it out yet, I'd highly recommend the Parse Anypic tutorial which has a very similar structure