我试图按客户公司名称订购我的所有项目,但我收到此错误: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(…)
一切正常。
答案 0 :(得分:7)
您需要使用references
编写它。
Project.includes(:customer)
.order("LOWER(customers.company) ASC")
.references(:customers)