我正在尝试使用 ActiveRecord 实现多表继承。看起来所有可用的 gem 都很老了。我错过了什么吗?是否有任何“ native ”方法可以使用 activerecord 实现这一点?
我正在使用 Rails 3.2.3 和 activerecord 3.2.1
最佳答案
Rails 6.1+ 委托(delegate)类型
Rails 6.1 添加了一种“原生”方式来通过 delegated type
实现多表继承.
见 the corresponding PR for details .
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.
关于ruby-on-rails-3 - 多表继承 Rails 和 activerecord,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15753146/