Javier Valencia
Javier Valencia

Reputation: 695

Deep eager load on rails

In this thread know how to make a eager load in rails, but how to do this nested?

I.e:

# get category, random product and random photo
@category = Category.find(params[:id], :include => random_product, :include => random_photo)

I don't know if I explain...

Thanks in advance.

Upvotes: 2

Views: 662

Answers (1)

Zargony
Zargony

Reputation: 10145

You can eager load nested associations by giving a hash to the :include option:

@category = Category.find(params[:id], :include => { :random_product => :random_photo})

Upvotes: 4

Related Questions