ruby-on-rails-3 - 多表继承 Rails 和 activerecord

标签 ruby-on-rails-3 activerecord class-table-inheritance

我正在尝试使用 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/

相关文章:

ruby-on-rails - ruby 正则表达式 - 如何匹配所有内容直到字符 -

ruby-on-rails - Rails 按 has_many 关联的结果计数排序

sql - 我们如何实现 IS-A 关系?

mysql - 一种子类型的 SQL 具体与类表继承查询速度

ruby-on-rails - rails3 devise - 没有路由匹配 "/sessions/user"

ruby - 您如何禁止记录某个特定操作的日志记录?

mysql - YII 库存控制系统问题

ruby-on-rails - 根据子项的特定属性对 ActiveRecord 实例进行排序

ruby-on-rails-3 - Rails 3 中的类表继承

ruby-on-rails - 路由无法正常工作