假设我有以下 DataMapper 资源:
class Post
include DataMapper::Resource
has n, :comments
...
end
class Comment
include DataMapper::Resource
belongs_to :post
...
end
要获得有序的帖子列表,我知道你可以这样做:
@posts = Posts.all(:order => :date.desc)
但是假设我想显示所有按评论数量降序排列的帖子。我该怎么做?