如何在模型上放置多个默认范围?
我想知道如何在模型上有多个默认范围(排序),例如我有一个评论模型,需要按日期排序并批准:
default_scope :order => 'approved ASC', :order => 'date ASC'
那么如何将这两个排序放在模型上,所以我首先订购按批准,然后按日期。
干杯!
I was wondering how do you have multiple default scopes (ordering) on a model for example I have a comments model that needs ordering by both date and approved:
default_scope :order => 'approved ASC', :order => 'date ASC'
So how do you have both of these ordering put on a model, so I first orders by approved, and then by date.
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Rails 4+ 中你可以这样做:
In Rails 4+ you can do:
以下是使用多个字段进行排序的良好语法:
Here is the good syntax for ordering with several fields :