Hey helpful people! Hopefully this question makes sense!
I am creating a stories app, where other users vote on the stories (a thumbs up or thumbs down vote). I want to know how to:
count the votes
Where should the votes be recorded in the database (ie a component within the stories or a new collection?)
how do i display the thumbs up votes as a percentage of all votes on the story page?
Where to store the votes - that depends on what you want. If you don’t want to limit users from voting multiple times, you could just add 2 properties (upvote and downvote) for the story and then increase them.
Or you could create a separate “votes” database table, and store “relation to user” - “relation to story” - “upvoted” - “downvoted” records for each user-story vote. And then calculate the number based on Count.
Thanks so much for these resources. I have read through both, but still confused unfortunately (sorry!!). So:
Favourite Button tutorial:
My users essentially have 2 relationships to stories (a. 1 user can create many stories, b. many users can vote on many stories) - does this mean I have to create a different relationship for each type? ie 2 relationships in this case, one being 1:many and another many:many?
There is functions for toggle but essentially I have a like and dislike button so I want each to be able to toggle on and off but also to restrict a user to a single option (either like or dislike) and also to a single vote (you can change your mind but its still only counted as one vote)
Or do I set up 3 relationships a. 1 user can create many stories b. many users can like many stories c. many users can dislike many stories?
Follow Tutorial:
This was really great to know (although a little confusing!) so as soon as I understand the answers to the above questions I will implement the ‘follow’ but change it for the votes
You: Where to store the votes - that depends on what you want. If you don’t want to limit users from voting multiple times, you could just add 2 properties (upvote and downvote) for the story and then increase them
Me: I definitely want to limit users to not only voting once but also only allowing them to like or dislike, not both. So you are saying to either add votes as a property of stories or to create a new votes collection?
Also, is there a way to display percentage? ie what percentage of voters liked the story rather than just count?