Johnston
Johnston

Reputation: 20884

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

Upvotes: 6

Views: 5416

Answers (1)

James
James

Reputation: 4807

Don't pluralize activity_type.

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

Upvotes: 9

Related Questions