Reputation: 42977
I'am making an app backed up with Parse
. Its a simple app which shares photos and others can like,comment on it. I'am getting confused in designing proper post
model in NoSQL
way. i'am considering designing like Post
contains
Post
Now the problem is how can i indicate the current user liked the post or not? One way is to fetch all the liked posts and do a filtering in client side. That wont be an optimal solution and requires more than one request. How can i handle this scenario efficiently in server side?
Ultimately i want it like
Upvotes: 4
Views: 213
Reputation: 16884
The easiest way is with two queries.
Assuming your Like
class includes a pointer back to the Post
class, your query logic could be like the following:
Post
rows for the top 20 sorted by created_time
descending, default the user_has_liked
property to falseLike
rows where post
matches the above post query and user
matches the current userYou can learn about the "matches query" here:
https://parse.com/docs/android_guide#queries-relational
Upvotes: 1