My group model has_many posts, posts have_many comments.
When I show the posts on a group, I want to order by the created at of the most recent comment, if there are any on a post, or by the created_at of the post itself.
So an old post would jump back to the top of the list if it has a new comment.
I would stick to a little different approach: your
Comment belongs_to :postandbelongs_toaccepts:touchoption. Set it totrueand your Post’supdated_atwill be automatically updated on a Comment’s modification. This way you can freely show your posts ordered by theirupdated_at.