【发布时间】:2015-05-15 16:58:36
【问题描述】:
给定下面的 ActiveRecord 模型:
class Model < ActiveRecord::Base
has_many :group_assignments
has_many :product_assignments
# Only one of the next two should appear, based on condition
has_many :products, through: :product_assignments
has_many :products, through: :group_assignments
end
希望根据以下条件定义最后一个 has_many...through 关系:如果模型有与之关联的任何产品分配,则产品来自产品分配。如果模型没有 product_assignments,则产品来自 group_assignments。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 activerecord