2014-02-28 4 views
0

I 3 개 모델레일 어레이 연결

class A < ApplicationController 
    has_many :b 
end 


class B < ApplicationController 
    has_many :c 
    belongs_to :a 
end 


class C < ApplicationController 
    belongs_to :b 
end 

I 터미널에 물품과 레일의 관계를 가지고

A.first.b.first.c 

완벽하게 작동

하지만 물품

A.first.b.c 
A.first.b.all.c 

다음 레일 r eturn array []

어떻게하면 A.first와 관련된 모든 c 모델을 얻을 수 있지만 연관에서는 사용하지 않습니다.

답변

0

당신은 map 사용할 수 있습니다

A.first.b.map(&:c)