我在3个模型之间的rails中有关联
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
然后rails返回数组[]
如何获得与A.first关联的所有c模型,但在关联中没有使用槽。
答案 0 :(得分:0)
您可以使用map
:
A.first.b.map(&:c)