class Post
has_many :commments
end
class Comment
belongs_to :post
end
I wish to display a list of posts
ordered by date of post
creation (submitted_at
). I also want some post
xyz to appear at the top if it has some new comment posted and yet to be reviewed by moderator. We will determine this by a boolean
attribute/field at comments level (moderated = 1/0)
I tried
Posts.join(:comments)
.distinct
.order("submitted_at DESC, comments.moderated")
but this excludes posts that have no comments
and results aren't sorted as expected. I am sure that we can do this at ruby level, but looking for a way to do this using AR.