Creating a Voting system

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:

  1. count the votes
  2. Where should the votes be recorded in the database (ie a component within the stories or a new collection?)
  3. how do i display the thumbs up votes as a percentage of all votes on the story page?

sorry if that didn’t make sense?

Hi @robrea,

I would recommend to have a look at this tutorial: How to create a "Favorite" button - Adalo Resources
Also, this one could be useful: How to Allow Users to Follow Others - Adalo Resources
Replace “favorites” or “follow” with “Thumbs Up” and you may start from there :slight_smile:
If you use these as a basis, then you can allow users to “remove” their votes at any time.

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.

Hi Victor,

Thanks so much for these resources. I have read through both, but still confused unfortunately (sorry!!). So:

Favourite Button tutorial:

  1. 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?
  2. 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)
  3. 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:

  1. 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?

Thanks so much for your help Victor!!