【发布时间】:2017-12-26 13:32:58
【问题描述】:
无论我尝试什么,我都无法按标题进行排序。这是电流输出 - http://take.ms/M3W2Z,基本上是 A 在 N 之后,B 在 A 和 N 之后等等等等。
我的模型:
class Manufacturer < ApplicationRecord
has_many :products
end
class Product < ApplicationRecord
belongs_to :manufacturer
scope :by_alphabet, -> { order('title DESC' ) }
end
我的看法:
-@manufacturer.products.by_alphabet.each do |product|
=product.title
我试过scope :by_alphabet, -> { order('products.title DESC') },但也没有用。
我是否遗漏了一些如此明显的东西?这只是一个简单的排序......还是关于西里尔字母的问题?我试图用俄语字母对一个简单的数组进行排序 - 它就像一个魅力。
【问题讨论】:
-
表中字段的编码和排序规则是什么?
-
如果我确实查对了:
Manufacturer.find("moroshka-sladkaya-6m").products.first.title.encoding Manufacturer Load (0.2ms) SELECT "manufacturers".* FROM "manufacturers" WHERE "manufacturers"."slug" = $1 LIMIT $2 [["slug", "moroshka-sladkaya-6m"], ["LIMIT", 1]] Product Load (0.3ms) SELECT "products".* FROM "products" WHERE "products"."manufacturer_id" = $1 ORDER BY "products"."id" ASC LIMIT $2 [["manufacturer_id", 2], ["LIMIT", 1]] => #<Encoding:UTF-8>