STI is a good approach, but my "subtables" have additional attributes
and afaik this isn't supportet by STI, is it?
For example:
user << Base
id
firstname
lastname
address
end
employee << user
<all of the above and additionally:>
salary
end
In the past I used a framework that supported other techniques besides
Single-Table Inheritance. There were actually two other options that
were called Horizontal and Vertical Inheritance. Of those options
Vertical Inheritance was the closest to what we think of as object
inheritance (as you described above), but was also the least efficient.
The issue is that both Horizontal and Vertical inheritance require
multiple queries to get to all the data you need, which causes
performance problems. Even with a framework that supported the other
techniques, using STI was strongly recommended. The performance costs of
either Horizontal or Vertical was simply too high. Inheritance doesn't
map well to RDBMS. The cost of the null fields in a single table that
contains all attributes for the entire inheritance hierarchy is
negligible compared to the other techniques.
Honestly, I've always preferred single-table inheritance. I am new to
Rails, but in Java, this is what I've always done and it just works
really nicely and it's more performant than forcing multiple joins
whenever you want to query users - which is probably going to be
often.
I am finding other problems that are Rails-specific with subclasses...
like when submitting forms with simple_for, the parameters hash isn't
the base class by default, so I am having trouble forcing it to be the
base-class... but structurally, single-table inheritance is a sound
practice. Been doing it for over a decade.