I have a project which needs to use an agregrate function to sort and return relevant records from one of my active record models. Problem is, despite seeing it used on numerous rails tutorials, and despite it being in the online ActiveRecord documentation, my Rails app throws this error at me when the method is called:
Unknown key(s): having
Any ideas why?
I am using it like this (I do have a :group =>
before it which works, as without the :having the code executes properly, it's just not filtered - which I need.):
Question.find(
:all,
:select => "questions.id, questions.text, questions.question_type_id, questions.meta, questions.max_answer_length, CAST(COUNT(form_questions.id) AS REAL) / CAST((SELECT COUNT(*) FROM application_forms) AS REAL) AS expr1",
:joins => "INNER JOIN form_questions ON questions.id = form_questions.question_id",
:order => "expr1 DESC",
:group => "questions.id, questions.text, questions.question_type_id, questions.meta, questions.max_answer_length",
:having => ["expr1 >= ?", 0.75]
)