【发布时间】:2020-09-15 18:25:16
【问题描述】:
has_many, through: association 加入模型是否有可能具有关联? 假设有这个关联,我有一个产品列表,其中有很多不同的价格,每个价格都与一个国家/地区相关联。因此,我可以获取我的产品在哪些国家/地区可用,也可以在一个国家/地区获取每种产品。
产品
has_many :prices
has_many :countries, through :prices
价格
belongs_to :product
belongs_to :country
国家
has_many :prices
has_many :products, through :prices
现在我想在我的价格模型中添加其他关联,其中价格 has_one :currency,价格由该信息所属的用户定义。是否可以像这样添加关联?
价格
belongs_to :product
belongs_to :country
has_one :currency
belongs_to :user
【问题讨论】:
标签: ruby-on-rails