【发布时间】:2012-06-05 12:13:33
【问题描述】:
如果模型Store、Product、User 和Price 具有以下关联
class User < ActiveRecord::Base
has_many :products
has_many :stores
has_many :prices
end
class Store < ActiveRecord::Base
belongs_to :user
has_many :prices
end
class Product < ActiveRecord::Base
belongs_to :user
has_many :prices
end
class Price < ActiveRecord::Base
belongs_to :user
belongs_to :product
belongs_to :store
end
class Estate < ActiveRecord::Base
belongs_to :user
end
并且想要创建一个Option 模型,该模型包含模型特定选项类型,例如,如果庄园有后院、游泳池、网球场或价格有交易、折扣或买一送一。这会通过多态关联来完成吗?
我这样做是为了不必为每个模型创建一个选项模型,并且可以只为我想要添加的所有新选项创建一个模型。那么这是解决这个问题的正确方法吗?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3.1 rails-activerecord