【发布时间】:2026-01-18 23:55:02
【问题描述】:
在 Rails 3.2.17 中,我可以有以下内容:
scope :sorted, -> { joins(:other).order({:other => :code}, :code) }
这会产生以下 SQL:
SELECT [things].* FROM [things] INNER JOIN [others] ON [others].[id] = [things].[other_id] ORDER BY [others].[code] ASC, [things].[code] ASC
但是,Rails 4.0.4 中的相同代码会出现以下错误:
Direction should be :asc or :desc
但是,我想不出一种方法来保持顺序并指定直接。例如,下面的范围给出了相同的错误:
scope :sorted, -> { joins(:other).order({:other => {:code => :asc}}, :code => :asc) }
编辑:明确地说,我想使用哈希样式语法,不想编写原始 SQL 字符串
【问题讨论】:
标签: sql ruby-on-rails activerecord ruby-on-rails-4