如何命令关联列不区分大小写

时间:2015-07-14 14:25:38

标签: ruby-on-rails ruby postgresql activerecord

我试图按客户公司名称订购我的所有项目,但我收到此错误:PG::UndefinedTable: ERROR: missing FROM-clause entry for table "customers" LINE 1: ... WHERE "projects"."archived" = $1 ORDER BY LOWER(customers.... ^ : SELECT "projects".* FROM "projects" WHERE "projects"."archived" = $1 ORDER BY LOWER(customers.company) ASC

这是我到目前为止尝试的方式:

projects = Project.includes(:customer).order("LOWER(customers.company) ASC")

如果我遗漏LOWER(…)一切正常。

1 个答案:

答案 0 :(得分:7)

您需要使用references编写它。

Project.includes(:customer)
       .order("LOWER(customers.company) ASC")
       .references(:customers)