2014-02-28 132 views
0

我在導軌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 

當我在終端寫之間的關聯:

A.first.b.first.c 

作品完美

但是當我寫

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

then rails r eturn array []

如何獲取與A.first相關的所有c模型,但是沒有在關聯中使用低谷。

回答

0

您可以使用map

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