The project uses the friendly_id gem on the name field. How to sort the query? If you do something like: Model.all.order(name: :asc) , then the sorting is ultimately across the slug field, but since name in Russian there is a problem.
Update
model job.rb:
extend FriendlyId friendly_id :name, use: [:slugged, :finders] model example.rb:
belongs_to :job I'm trying to do something like this:
ExampleJob.all.includes(:job).order("LOWER('jobs.name') DESC") I also tried:
Job.where(id: ids_arr).order(name: :desc) Logs:
Job.all.order(name: :desc) Job Load (2.5ms) SELECT "jobs".* FROM "jobs" ORDER BY "jobs"."name" DESC => [#<Job:0x007fd316133558 id: 2, name: "Диагностика", created_at:..., slug: "diagnostika">, #<Job:0x007fd316133328 id: 3, name: "Установка", created_at: ..., slug: "ustanovka">, #<Job:0x007fd3161330a8 id: 1, name: "Замена", created_at: ..., slug: "zamena">] Ie the name should have been: Diagnostics, Replacement, Installation, obviously all the same here sorted by slug
PS postgresql 9.3 db
Job.all.order(name: :desc).explain Job Load (0.9ms) SELECT "jobs".* FROM "jobs" ORDER BY "jobs"."name" DESC => EXPLAIN for: SELECT "jobs".* FROM "jobs" ORDER BY "jobs"."name" DESC QUERY PLAN -------------------------------------------------------------- Sort (cost=51.37..53.17 rows=720 width=84) Sort Key: name DESC -> Seq Scan on jobs (cost=0.00..17.20 rows=720 width=84) (3 rows)
slugsorting, unless you explicitly indicate this, for example in the model. Will you be able to supplement the question with code from the model with which you connect FriendlyId to it? - Vitaly EmelyantsevJob.all.order(name: :desc).pluck(:name)- D-side