Using Single Table Inheritance (STI) in Rails

1
  • Assuming a rails project with the Livestock, Agriculture, Fish farming and improvement.
  • Being these inherit the properties of a model called Activity and are considered Activity types.
  • The templates do not accurately inherit specific methods or behaviors, in case only the inherited properties access
  • But some models have properties other than inherited and others not, for example Agriculture, in addition to the inherited ones, has the Agricultural Group properties and Agricultural Type.

Having this in mind comes my doubts:  1ª Is it a favorable scenario for the use of the Single Table Inheritance (STI) technique?  In the case of models that have only the inherited properties, how can I avoid creating a new persistence table or model?.

    
asked by anonymous 05.05.2015 / 18:55

1 answer

2

If the models will inherit a considerable number of attributes and will implement common behavior, yes, it is a good option.

Using postgres 9.4 with rails 4.2 you can do it in a very transparent way.

I recommend reading these posts for an idea of how to implement:

link

link

    
05.05.2015 / 20:05