1
说我们有:如何比多态关联更好的方式分享轨道3与其他数据库模型的模型
class ProductProperties < ActiveRecord::Base
belongs_to :sellable, :polymorphic => true, :dependent => :destroy
end
class Tee < ActiveRecord::Base
has_one :product_properties, :as => :sellable, :autosave => true
end
class Pen < ActiveRecord::Base
has_one :product_properties, :as => :sellable, :autosave => true
end
的,我们可以解决产品特性: @ Tee.productProperties.property或@ Pen.productProperties.property
有没有办法简单地访问@ Tee.property和@ Pen.property?
这将使它更简单,因为T恤和Pen每个人都有自己的属性(例如:@ Pen.ownProperty)
到目前为止,我的研究使我这个插件: https://github.com/brunofrank/class-table-inheritance。 有没有人使用过它,并使用它是一个好主意(我的直觉是,这将在每个新的rails版本中打破)?
谢谢!