I have a use case where a User can perform a Test. This is based on an Invite. So an admin can send an Invite to a User to perform a selected Test. It is also possible to create a Team of several Users and send an Invite to all the users of a Team to perform the Test for that Team.
There are several options to create these models, but I am not sure what is the best way (or perhaps there is even an alternative).
Option 1
- User: id, name
- Team: id, name
- UserTeam: user_id, team_id
- UserInvite: id, user_id
- TeamInvite: id, team_id
- Test: id, user_id, user_invite_id (can be null), team_invite_id (can be null), type [user|team]
Option 2
- User: id, name
- Team: id, name
- UserTeam: user_id, team_id
- Invite: id, user_id (can be null), team_id (can be null), type [user|team]
- Test: id, user_id, invite_id
So is it better to have seperate invites (for teams and users) and link the tests to a team-invite or a user-invite (like option 1). Or the alternative: have a single invite and determine then if it’s linked to a team or a user (like option 2)?
Personally, I’d go with your second option.
You might also want to investigate this third option, however. It makes it possible to store an invite sent to multiple teams and users: