Set default order of a has_many resource at the Active Record level

Viewed 10675

How do you set the default order of resources coming out of the db. Something like:

has_many :trips, :order => 'departure_date DESC'

There is some business logic that needs the most recent date being checked first.

Current code results in this error.

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):

Was trying this as it received good reviews (6yrs ago.) Am I missing something simple or has that be depricated in favor of a better way today?

1 Answers
Related