制造商
has_many :product
产品
has_many :part
PartsRequest
belongs_to :part
belongs_to :manufacturer
我正在尝试在PartsRequest中做一些事情 例如制造商A正在尝试从制造商B请求零件
scope :incoming_requests, lambda { |manufacturer_id|
joins(:part).joins(product).where("product.manufacturer_id = ?", manufacturer_id)
}
如何加入零件,然后从零件加入产品?
答案 0 :(得分:4)
scope :incoming_requests, lambda{|mid| joins(:part => :product).where(:product => {:manufacturer_id => mid}) }