Single Table Inheritance: Good spot or not?
I have two simple models I'm about to create in an existing Rails app. One is a NAICSCode
which has the following attributes: company_id
, code
, name
, and description
, the other is SICCodes
which has those same attributes, plus an attribute called year_first_appeared
.
Both models are just wrappers around data storage for those attributes (no individual methods at this point), and both belong_to
Company
(which does have functionality and a purpose).
If these actually did anything besides store related data, I can see an advantage of creating a Code
object (model) and using STI, with SIC
or NAICS
being a type.
Without any methods is there any benefit besides having one less table in the database?
I can't think of any other benefits. "Simpler" to manage from a database perspective, but complexity shifts to working with STI.
In this case, I usually do whatever feels easiest and just keep in mind that I need to be careful to consider this in the future anytime I start changing these around. Whatever you decide later on, you should be able to easily combine or separate these into different tables.
Ya, I'm on the fence. STI is really nice early on, but it's been a bit difficult for me to work with as apps get more complex. You may only have one differentiator now, but in the future you may have several which you'll have to work in. Something to watch out for.