I’m currently building functionality that would al...
# prisma-whats-new
s
I’m currently building functionality that would allow users to upvote a post. However I want only allow to do it once per post. Does anyone know how I could do that. Should I store the user Id in a list once they have upvoted and check against that?
d
f
StackExchange does use a separate table for Votes, I think it makes sense
You could have a model of this sort
Copy code
type Vote @model {
  createdAt: DateTime!
  updatedAt: DateTime!
  id: ID! @isUnique
  type: VoteTypes!
  user: User! @relation(name: "VoteOnUser")
  post: Post! @relation(name: "VoteOnPost")

}
enum VoteTypes {
  UPVOTE
  DOWNVOTE
}
(If you want to handle down votes as well)
s
Ah sorry just saw these responses that’s very helpful. Yeah I was wondering if a separate table would be the way to go. How would you go about checking if a user had already voted on a particular post.
n
you don't have to do that. you just count one vote per user in the frontend