Nested Includes in Ruby on Rails 3
-
12-11-2019 - |
Question
In Ruby on Rails I have School which has many children. Children which has many activities. And Activity which has one activity_types. I need help nesting includes. In my Children Controller. I have this... which works.
s = School.find(params[:school_id])
@school = s
@children = s.children.includes(:activities).all
But I want to also get the :activity_type from the activities from the children. I tried this
s = School.find(params[:school_id])
@school = s
@children = s.children.includes(:activities => :activity_types).all
But that did not work
Solution
Don't pluralize activity_type
.
s.children.includes(:activities => :activity_type).all
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow