class Post
has_many :tags
class Tag
belongs_to :post
I need a query that returns all posts limited to n per tag.
Given the following set of posts (tagged with hashtags like on Twitter):
#1: Post A #letter
#2: Post B #letter
#3: Post 1 #number
#4: Post C #letter
#5: Post 2 #number
I would want to get all of the latest 2 posts per tag, giving me the following result:
#5: Post 2 #number
#4: Post C #letter
#3: Post 1 #number
#2: Post B #letter
I've been looking up how to do this for a few hours now, but only found results (like this) that use MySQL variables and don't know how to translate it to Rails.
I still don't know where to begin tackling this so any help is appreciated; thanks!