在Active Record级别设置has_many资源的默认顺序

Che*_*Fry 6 ruby-on-rails

如何设置数据库的默认资源顺序.就像是:

has_many :trips, :order => 'departure_date DESC'
Run Code Online (Sandbox Code Playgroud)

有一些业务逻辑需要首先检查最近的日期.

当前代码导致此错误.

ArgumentError (Unknown key: :order. Valid keys are: :class_name,     :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type):
Run Code Online (Sandbox Code Playgroud)

正在尝试这个,因为它收到了很好的评论(6年前.)我是否遗漏了一些简单的东西,或者是否有人为了今天更好的方式而被贬低?

Mat*_*att 18

has_many :trips, -> { order(departure_date: :desc) }
Run Code Online (Sandbox Code Playgroud)

向下滚动到"范围"