ActiveRecord eager-loading thru multiple associations

I just found out how to do something I have been wondering for a long time: :include syntax to eager-load through multiple associations. In the rdoc for class ActiveRecord::Associations::ClassMethods I discovered you can nest include statements in hashes as follows: If for example table_a has_many table_b and table_b has_many table_c and table_c has_many table_d:

Model.find :first, :include => { :table_a => { :table_b => { :table_c => :table_d } } }

You must be logged in to post a comment.