Reputation:
From an Organization table two other tables are hanging with belongs_to
and has_many
associations, they both have that organization_id key.
So for eager loading I wrote this:
@organization = Organization.includes(:population_summaries, :key_performance_inds).find(params[:id])
This should work.
But now I have a third table to include in there. key_performance_interval which has that kpi_id
field that is used as foreign key to point to key_performance_int table. I can't get that part to write and add to my eager loading section. How should I add that one?
Upvotes: 0
Views: 74
Reputation: 2675
To included nested associations, you write it as a hash:
@organization = Organization.includes([:population_summaries, key_performance_inds: :key_performance_interval]).find(params[:id])
You can read about it on this rails guide under section 12.1.2
Upvotes: 1