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.
EDIT: In response to J. since I can't seem to format code inside the comments field
Would you be able to nest the :through relationship? say...
class Category < ActiveRecord::Base
has_many :posts
has_many :comments, :through => posts
has_many :ratings, :through => comments
end
class Post < ActiveRecord::Base
belongs_to :category
has_many :comments
has_many :ratings, :through => comments
end
class Comment < ActiveRecord::Base
belongs_to :post
has_many :ratings
end
class Rating < ActiveRecord::Base
belongs_to :comment
end