假设我有一个机制模型,它的架构是这样的:
t.string "image"
t.string "type"
t.string "speed"
t.string "name"
现在假设我想创建一个名为Car的子模型,该子模型使用STI(Car < Mechanism
)完全继承了Mechanical模型字段,但也应用了自己的子模型:
t.string "wheels"
t.string "metal_type"
t.string "fuel_consumption"
...
最后,我基本上希望拥有许多模型,这些模型与机制模型共享某些db字段,并且表现得像机制一样。
现在我知道STI不能这样工作,但是我想知道我还有其他选择吗?
您可以使用一种继承性宝石。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句