Anil Varghese
Anil Varghese

Reputation: 42977

Parse: Posts with the indication of logged in user liked or not

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

enter image description here

Upvotes: 4

Views: 213

Answers (1)

Timothy Walters
Timothy Walters

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:

  • Get Post rows for the top 20 sorted by created_time descending, default the user_has_liked property to false
  • Get Like rows where post matches the above post query and user matches the current user
  • Update the post rows for any matches found

You can learn about the "matches query" here:

https://parse.com/docs/android_guide#queries-relational

Upvotes: 1

Related Questions