使用squeel gem我不断收到错误。 Ruby On Rails

时间:2015-12-29 13:32:02

标签: ruby-on-rails ruby ruby-on-rails-4 activerecord

我正在尝试使用squeel gem在活动记录查询上执行group_by。我一直收到这个错误 - >

ActiveRecord::StatementInvalid (OCIError: ORA-00936: missing expression: SELECT "TO_ENTRIES".* FROM "TO_ENTRIES" WHERE ("TO_ENTRIES"."EMP_DEPT" LIKE any('PLTDUP', 'PLTINS') AND "TO_ENTRIES"."AUTH" = 'E' AND ("TO_ENTRIES"."APPROVE_DISAPPROVE" LIKE '1' OR "TO_ENTRIES"."APPROVE_DISAPPROVE" LIKE '2'))): app/controllers/entry_controller.rb:115:in `index'

如果我离开group_by它的工作问题是我真的需要group_by。

任何帮助都将非常感谢!!!

entry_by_start_date = Entry.where{(emp_dept.like any t) & (auth == 'E') & (approve_disapprove.like_any a_d)}.group_by {|i| i.leave_start.to_date}
entry_by_end_date = Entry.where{(emp_dept.like any t) & (auth == 'E') & (approve_disapprove.like_any a_d)}.group_by {|i| i.leave_end.to_date}

2 个答案:

答案 0 :(得分:0)

这应该有效

entry_by_start_date = Entry
                        .where{(emp_dept.like any t) & (auth == 'E') & (approve_disapprove.like_any a_d)}
                        .group(:leave_start)
entry_by_end_date = Entry
                      .where{(emp_dept.like any t) & (auth == 'E') & (approve_disapprove.like_any a_d)}
                      .group(:leave_end)

答案 1 :(得分:0)

错误OCIError:ORA-00936:缺少表达式:

由于忘记了选择或分组中的列列表而发生

你可以尝试

entry_by_start_date = Entry.group(:leave_start).select{[leave_start.to_date]}.where{(emp_dept.like any t) & (auth == 'E') & (approve_disapprove.like_any a_d)}

entry_by_end_date = Entry.group(:leave_end).select{[ leave_end.to_date]}.where{(emp_dept.like any t) & (auth == 'E') & (approve_disapprove.like_any a_d)}