Rails nested has_many association, how to get, say, last 5 of all children?

Posted by Randuin on Stack Overflow See other posts from Stack Overflow or by Randuin
Published on 2010-06-09T16:46:28Z Indexed on 2010/06/09 16:52 UTC
Read the original article Hit count: 128

Filed under:

Let's say that

Post has_many :comments

and that

Comment has_many :ratings

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails