Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Table Inheritance or Class Table Inheritance?

I'm reading about Class Table Inheritance (CTI) and finding I prefer it overall. The question I have is, is there any specific use case for Single Table Inheritance (STI) where you'd use that over CTI?

I read http://rhnh.net/2010/07/02/3-reasons-why-you-should-not-use-single-table-inheritance and as far as I know, it's solid. The use case for STI being a difference in behaviour but not data.

like image 999
SpaceGhost Avatar asked May 20 '11 14:05

SpaceGhost


People also ask

How does the single table inheritance work?

In Single-Table Inheritance (STI), many subclasses inherit from one superclass with all the data in the same table in the database. The superclass has a “type” column to determine which subclass an object belongs to. In a polymorphic association, one model “belongs to” several other models using a single association.

What is single table inheritance in rails?

Single-table inheritance (STI) is the practice of storing multiple types of values in the same table, where each record includes a field indicating its type, and the table includes a column for every field of all the types it stores.

What is a single table?

The single table strategy is one of the most simplest and efficient way to define the implementation of inheritance. In this approach, instances of the multiple entity classes are stored as attributes in a single table only. The following syntax represents the single table strategy: -

What is SQL table inheritance?

SQL object inheritance is based on a family tree of object types that forms a type hierarchy. The type hierarchy consists of a parent object type, called a supertype, and one or more levels of child object types, called subtypes, which are derived from the parent.


1 Answers

I would like to point you to a great article I have found that explains with clarity why and when to use CTI. LINK

like image 148
Gerry Avatar answered Oct 08 '22 15:10

Gerry