【发布时间】:2017-12-06 14:55:47
【问题描述】:
我正在尝试使用baby_squeel 编写一个相当复杂的查询。该查询需要使用coalesce SQL 函数。 coalesce 在 baby_squeel 主页上多次用作示例,但是当我尝试在查询中使用它时,我得到一个 no method 错误。
下面的例子:
result = Table.selecting { |t| [t.col1,
((coalesce(t.col2, 0) + coalesce(t.col3, 0)).sum.as('column'))] }
.where.has { |t| t.col4 == 'some condition' }
.grouping { |t| t.col1 }
我正在使用 Rails 5 和 baby_squeel 1.2。该查询在私有控制器函数内部调用。
为什么会这样?我是否需要 require 或使用 arel 自己定义函数?
【问题讨论】:
标签: ruby-on-rails arel coalesce squeel