Sle*_*vin 1 ruby postgresql activerecord ruby-on-rails
我正在尝试按客户公司名称订购我的所有项目,但是我收到了这个错误: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")
Run Code Online (Sandbox Code Playgroud)
如果我遗漏LOWER(…)一切正常.
你需要用它来写references.
Project.includes(:customer)
.order("LOWER(customers.company) ASC")
.references(:customers)
Run Code Online (Sandbox Code Playgroud)