2011-11-10 3 views
1

제조업체에게레일 중첩는

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) 
} 

어떻게 부품에 연결 한 다음 부품을 제품에 연결합니까?

+2

'조인 (: 부분 => : 제품)'을 찾고 계시거나 더 복잡합니까? – mnelson

+0

나는 그것이 효과가 있다고 생각한다. 감사! –

답변

4
scope :incoming_requests, lambda{|mid| joins(:part => :product).where(:product => {:manufacturer_id => mid}) }