[code language=”ruby”]Article.joins(:comments).group("articles.id").order("max(comments.created_at) DESC")[/code]