【问题标题】:How to order associated columns case insensitive如何排序关联列不区分大小写
【发布时间】:2016-01-25 22:42:30
【问题描述】:

我正在尝试按客户公司名称订购我的所有项目,但我收到此错误: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(…) 一切正常。

【问题讨论】:

    标签: ruby-on-rails ruby postgresql activerecord


    【解决方案1】:

    您需要使用references 编写它。

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

    【讨论】:

      猜你喜欢
      • 2019-02-06
      • 2019-01-31
      • 2020-09-13
      • 2012-06-22
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      相关资源
      最近更新 更多