【发布时间】:2016-12-27 15:24:20
【问题描述】:
问题:
人们可能拥有多种类型的学位(学士、硕士、博士等...)。 在我的国家,某些学位包括另一个学位。
例如:高级学位可以是学士或执照。
我想在类层次结构中创建这个结构:
Bachelor < Superior < Degree
Licentiate < Superior < Degree
Master < Degree
PHD < Degree
这些类不需要在数据库中存储行,但我想将它们与其他类的一些 ActiveRecord 对象相关联。
我应该将类名存储为字符串吗?
【问题讨论】:
-
使用多态关联。
-
single table inheritence 是你的朋友
-
我还没试过,但是多态不需要 {object}_id ? (我不会有)
标签: ruby-on-rails activerecord polymorphic-associations