I have a situation that I thought would be straightforward and fairly common but am having trouble locating resources on how to accomplish this. Perhaps I am just using the wrong terminology to search for on this.
Basically, I have a situation where I have an two entities (pseudocode below):
@Entity:
User {
int id;
String username;
}
@Entity
Datarecord {
User user;
String recordEntry;
}
I want to make it so that there can only be one DataRecord entry per User with the same recordEntry value. So, there can be many entries in the database with the same recordEntry but each one must be associated with a different user. Could anyone point me to resources on this. Thanks
I think what you need is a ManyToMany relationship between User and DataRecord. This will create a join table satisfying your criteria.
So while User table will have unique users and DataRecord table will have unique recordEntries, the join table will have records that map a user to multiple recordEntries. Correspondingly, a record entry will be mapped to multiple users.