Great answer from noodl ... thanks for that!
I needed to find - stick with the sample classes of the original question - 4 posts that were recently commented ... a small answer to noodl does the trick:
Post.select('posts.*, max(comments.created_at) as last_commented_at'). joins(:comments). group('posts.id'). order('last_commented_at DESC'). limit(4)
Thanks!
source share