Search code examples
sequel

How to order association in descending order in Sequel


Given this class

class User < Sequel::Model
  one_to_many :rounds, order: :date
end   

What I'm trying to do is sort by descending date.

I tried this like ActiveRecord supports, but that is not the way to go.

one_to_many :rounds, order: date: :desc

One solution is to create a dataset method but I feel there must be a better way to do this.


Solution

  • The way to do this is to use one of the many "builders" that come with Sequel.

    This time namely the Sequel.desc one.

    one_to_many :rounds, order: Sequel.desc(:date)