title: Rails nested has_many association, how to get, say, last 5 of all children?
body: <p>Let's say that</p>
  
  <pre><code>Post has_many :comments
  </code></pre>
  
  <p>and that</p>
  
  <pre><code>Comment has_many :ratings
  </code></pre>
  
  <p>How can I grab the last 5 comment ratings for each Post? I've been thinking of just looping through comment for each post but that wouldn't solve the Last 5 part.</p>
  
  <p><strong>EDIT</strong>: In response to J. since I can't seem to format code inside the comments field</p>
  
  <p>Would you be able to nest the :through relationship? say...</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    has_many :posts
    has_many :comments, :through =&gt; posts
    has_many :ratings, :through =&gt; comments
  end
  
  class Post &lt; ActiveRecord::Base
    belongs_to :category
    has_many :comments
    has_many :ratings, :through =&gt; comments
  end
  
  class Comment &lt; ActiveRecord::Base
    belongs_to :post
    has_many :ratings
  end
  
  class Rating &lt; ActiveRecord::Base
    belongs_to :comment
  end
  </code></pre>