title: Pulling multiple levels of data efficiently in Rails
body: <p>I am trying to build a print process, which consists of printing a batch of financial applications using Rails.</p>
  
  <p>I am printing around 100 applications, which consist of multiple levels of data (the application itself, sub-models, and their sub-models).</p>
  
  <p>At the moment the page is very inefficient as it is doing a lot of N+1 querying which is causing the performance to be poor.</p>
  
  <p>Question is, is there an efficient way of getting this data out of the database.  I've tried pulling the forms with <code>includes()</code> for all the sub-models, but this doesn't help with the models that are below that (for instance, <code>income_line_items</code> on a <code>financial_history</code> model)</p>
  
  <p>Any ideas?</p>