Can A Single Model Object Be A Parent Of Multiple Child Objects?
Solution 1:
Inheritance is not a great idea here. Use the OneToOne relationship instead. @mattm's claim that it doesn't support multiple inheritance is incorrect; the one-to-one limitation is per table, so you can indeed have a person who appears once in the Farmer table and once in the Preacher table.
Inheritance does exist in the database world, but it is not perfectly implemented by PostgreSQL at least, and since Postgres tends to have good standards conformance overall, this doesn't bode well for other database systems. I would not recommend relying on table inheritance unless you've reviewed the database system you will be using and confirmed it can support every aspect of your use case. In practice, this effort is not worth it when you can just use foreign keys to achieve much the same effect. Foreign keys and unique constraints (the building blocks of OneToOne) are very well supported on all modern database systems and will work correctly.
Post a Comment for "Can A Single Model Object Be A Parent Of Multiple Child Objects?"