【问题标题】:How to order association in descending order in Sequel如何在 Sequel 中按降序排列关联
【发布时间】:2020-08-14 09:22:10
【问题描述】:

给定这个类

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

我正在尝试按日期降序排序。

我尝试过像 ActiveRecord 支持一样,但这不是要走的路。

one_to_many :rounds, order: date: :desc

一种解决方案是创建数据集方法,但我觉得必须有更好的方法来做到这一点。

【问题讨论】:

    标签: sequel


    【解决方案1】:

    执行此操作的方法是使用 Sequel 附带的众多 "builders" 之一。

    这次就是Sequel.desc一个。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多