Subclassing Active Record?

Hi, I encountered the following text in Agile Dev with Rails 4th Ed.,
and I am quite confused. Can someone tell me what’s going on?


A number of column names have special significance to Active Record.
Here’s
a summary:

type

Active Record can be subclassed. When you do so, all of the attributes
for all of the subclasses are kept in the same table. The type attribute
is
used to name the column that will be used to track the type of a row.


Does “Active Record can be subclassed” mean subclassing a model?
Or subclassing ActiveRecord, which every model does.

Why would all subclasses of something be on same table, when they could
have different attributes?

I really can’t quite understand the paragraph.
Thanks!

Max Y. wrote in post #1004331:

Hi, I encountered the following text in Agile Dev with Rails 4th Ed.,
and I am quite confused. Can someone tell me what’s going on?


A number of column names have special significance to Active Record.
Here’s
a summary:

type

Active Record can be subclassed. When you do so, all of the attributes
for all of the subclasses are kept in the same table. The type attribute
is
used to name the column that will be used to track the type of a row.


Does “Active Record can be subclassed” mean subclassing a model?
Or subclassing ActiveRecord, which every model does.

Why would all subclasses of something be on same table, when they could
have different attributes?

This is talking about Single-Table Inheritance (STI). The type column is
used to distinguish the subclass the database table row represents. All
columns of the entire STI tree are keep in a single table. With STI
columns that are not related to a particular subclass contain null
values.

There are other schemes for this, but AFSIK Rails supports only STI.