class Post
has_many :comments
end
class Comment
# 表里有name这一栏
belongs_to :post
end
我想选出根据comments.size排序post,然后返回的类型是ActiveRecord::Relation.
写到这里写不下去了:Post.includes(:comments).order('comment.size DESC')。不知应该怎么在order里来表示排序。
类似还有如果我想选出某一个人的comment:Post.includes(:comments).where('comment.name = ?', name)?
请教应该如何做?谢谢!