0
votes

Django has Multi-table inheritance out of the box (https://docs.djangoproject.com/en/3.1/topics/db/models/#multi-table-inheritance). is there an equivalent solution in ruby on rails?

The closest I can find is either Polymorphic Associations or Single Table Inheritance (STI) or Abstract Base Classes but none of them is exactly what I need.

1

1 Answers

0
votes

The closest built-in solution to Rails is DelegatedTypes.

With this approach, the “superclass” is a concrete class that is represented by its own table, where all the superclass attributes that are shared amongst all the “subclasses” are stored. And then each of the subclasses have their own individual tables for additional attributes that are particular to their implementation.

This is similar to what's called multi-table inheritance in Django, but instead of actual inheritance, this approach uses delegation to form the hierarchy and share responsibilities.

It was added relatively recently, in Rails 6.1 - so the results of your google searches might pre-date it.