这似乎是一个非常简单的问题,但我还没有看到它在任何地方得到解答.
在rails中如果您有:
class Article < ActiveRecord::Base
has_many :comments
end
class Comments < ActiveRecord::Base
belongs_to :article
end
Run Code Online (Sandbox Code Playgroud)
为什么你不能用这样的东西订购评论:
@article.comments(:order=>"created_at DESC")
Run Code Online (Sandbox Code Playgroud)
如果您需要经常引用命名范围,甚至人们都会这样做:
@article.comments.sort { |x,y| x.created_at <=> y.created_at }
Run Code Online (Sandbox Code Playgroud)
但有些东西告诉我它应该更简单.我错过了什么?