Jpa Database relationships for a Voting system
-
26-06-2021 - |
Вопрос
There are many questions about voting systems so I will cut right to the chase.
My question is about relationships ,
import play.db.jpa.GenericModel;
public class VotesModel extends GenericModel {
@ManyToOne
public StatusModel status;
@ManyToOne
public UserModel user;
public Date time;
}
The usual voting rules apply,
- A status can have many votes
- A user can vote on many status.
- But a user can vote only once on a status .
I have easily applied the first 2 rules as @ManyToOne
, How do I apply the 3rd and most important rule?
Environment:
Playframework 1.2.5
, MySQL
Решение
Make a composite key out of status
and user
Не связан с StackOverflow