You can use map
:
A.first.b.map(&:c)
Question
I have an association in rails between 3 models
class A < ApplicationController
has_many :b
end
class B < ApplicationController
has_many :c
belongs_to :a
end
class C < ApplicationController
belongs_to :b
end
when I write in the terminal:
A.first.b.first.c
works perfectly
but when I write
A.first.b.c
A.first.b.all.c
then rails return array []
how can I get all the c models associated to A.first but withouth use trough in the associations.
Solution
You can use map
:
A.first.b.map(&:c)