首页 > 解决方案 > 如何在 Sequel 中按降序排列关联

问题描述

鉴于这个类

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

我想做的是按日期降序排序。

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

one_to_many :rounds, order: date: :desc

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

标签: sequel

解决方案


做到这一点的方法是使用Sequel 附带的众多“构建器”之一。

这次就是那个Sequel.desc

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

推荐阅读