Вопрос

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,

  1. A status can have many votes
  2. A user can vote on many status.
  3. 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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top