Nested Includes in Ruby on Rails 3

5.4k views Asked by At

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

1

There are 1 answers

2
James On BEST ANSWER

Don't pluralize activity_type.

s.children.includes(:activities => :activity_type).all