导轨阵列关联
问题描述:
我在导轨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模型,但是没有在关联中使用低谷。
答
您可以使用map
:
A.first.b.map(&:c)