title: Reduce queries in Rails request for multiple association levels
body: <p>I have four models that I am working with</p>
  <ul>
  <li>Collection</li>
  <li>Album</li>
  <li>Photo</li>
  <li>ActsAsTaggableOn::Tag</li>
  </ul>
  <p>Basically I am outputting a list of Collections, each one shows its Albums and I wish each Album to list all the tags that its containing Photos have.</p>
  <p>I currently have tried this query:</p>
  <pre><code>@collections = Collection.all.includes(albums: [photos: [:tags]])
  </code></pre>
  <p>It sort of helps but is still pulls out each tag separately by the looks of the log lines like:</p>
  <blockquote>
  <p>ActsAsTaggableOn::Tag Load (1.0ms)  SELECT &quot;tags&quot;.* FROM &quot;tags&quot; INNER JOIN &quot;taggings&quot; ON &quot;tags&quot;.&quot;id&quot; = &quot;taggings&quot;.&quot;tag_id&quot; WHERE
  &quot;taggings&quot;.&quot;taggable_id&quot; = $1 AND &quot;taggings&quot;.&quot;taggable_type&quot; = $2 AND
  &quot;taggings&quot;.&quot;context&quot; = $3  [[&quot;taggable_id&quot;, 85803], [&quot;taggable_type&quot;,
  &quot;Photo&quot;], [&quot;context&quot;, &quot;tags&quot;]] 23:10:56 web.1     |   ↳
  app/views/admin/gallery/gallery/index.html.erb:284</p>
  </blockquote>
  <p>Any ideas how to make this more efficient and faster?</p>