In trying to solve a problem I was having with having different types of the same table, I decided to go with the Party Model design for relational databases - using multiple tables to represent the sub-objects.
Using this post as well as this one as guides, I decided to construct a Party model using multiple table inheritance.
Here is a basic representation of what I'm doing (in pseudo sql):
Parties
- ID, AUTO_INCREMENT
- Type
- Shared_Data
- Primary Key (ID, Type)
User_Sub
- ID
- Type, Default 'U'
- User_Data
- Primary Key (ID, Type)
- Foreign Key 'User-Party' (ID, Type) references (Parties.ID, Parties.Type)
Organization_Sub
- ID
- Type, Default 'O'
- Organization_Data
- Primary Key (ID, Type)
- Foreign Key 'Organization-Party' (ID, Type) references (Parties.ID, Parties.Type)
Because data is spread across multiple tables, I'd like to be able to read from and update to the parent and child tables at once. Reading is fine, and can be done with a:
CREATE VIEW Users as
SELECT P.*, U.User_Data FROM Parties P
Inner Join Users_Sub U on P.id=U.id, P.type=U.type
But, inserting into both is not possible in MySQL (is it possible in other flavors?). Is it not possible to do multiple-table inheritance in such a manner? Putting all my User and Organization Columns into the Parties Table would probably solve this issue, but I'd be left with quite a few null fields.
Insight on this would be much appreciated.