Concreate table inheritance (CTI) or sometimes called leaf table inheritance represents an inheritance hierarchy of classes with one table per concrete class in the hierarchy.
In Ruby on Rails the ApplicationRecord
class would be the abstract class and User class would be the concrete class.
Relational databases don’t support inheritance.
CTI uses one database table for each concrete class in the hierarchy. The concrete table includes both the fields defined in the superclass as well as the concrete class.
CTI uses the inheritance mapper pattern. CTI must create an id
that is unique to all concrete classes sharing the same superclass. This requires the use of the indentify field pattern.
Advantages
- Each table is self-contained and has no irrelevant fields (as compared to single table inheritance)
- No SQL
joins
. - Each table is accessed only when the class is.
Issues
- Primary keys are problematic.
- Connot force database relationship to abstract classes.
- If the domain classes push fields up or down the hierarachy, then the tables have to be adjusted.
- If a superclass field is changed or added, all child class tables must be adjusted as well.