This is an example of "Joined Table Inheritance"
In this case the database will have three tables to segment "users":
- A base
userstable which will store the columns in the model definition forUserincluding thetypecolumn - A
participanttable which will store the participantid(which has a foreign key constraint to theusertable) and the specified attributes in theparticipantmodel (e.g.email_address) - A
hosttable which will store the hostid(which has a foreign key constraint to theusertable) and the specified attributes in thehostmodel (e.g.website)
For example:
- Create a new participant with a
username=peterandemail_address=peter@foo.bar.
- The
usertable will have a row with two columns:id:1, andtype:participant - The
participanttable will have a new row with two columnsid:1andemail_address:peter@foo.bar
(Note: both id columns have the same value because of the foreign key constraint)
- Querying for all
Userswill return bothParticipantandHostobjects - Querying for all
Participantswill return onyParticipantobjects (and the same forHost)