我正在尝试使用baby_squeel编写一个相当复杂的查询。查询需要使用coalesce SQL函数。在baby_squeel主页上有几次使用coalesce作为示例,但是当我尝试在查询中使用它时,我得到了一个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 }我使用的是Rails5和baby_squeel 1.2。该查询在私有控制器函数内部调用。
为什么会发生这种情况?我是不是需要用require来定义函数或者自己定义函数呢?
https://stackoverflow.com/questions/47677227
复制相似问题