ruby-on-rails-3nested-includes

Nested Includes in Ruby on Rails 3


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