我正在使用 rails ransack ( https://github.com/ernie/ransack ) 允许用户过滤和排序一些记录。我使用传统方法获得过滤和排序的记录。
@invoices = Invoice.search(params[:q]).result
现在我想获得一些摘要信息,所以我有
@invoices = Invoice.search(params[:q]).result
@summary = @invoices.select("sum(balance) as balance_total").first
除非用户指定要排序的字段。我收到 SQL 错误:
Column "project_name" is invalid in the ORDER BY clause because
it is not contained in either an aggregate function or the GROUP BY clause
我可以从范围中删除排序吗?如何?
谢谢