Rails has been spitting this out to me:
SQLite3::SQLException: near "SELECT": syntax error:
SELECT questions.id, questions.text, questions.question_type_id, questions.meta, questions.max_answer_length,
COUNT(form_questions.id) AS expr1,
(5) AS expr2,
CAST(COUNT(form_questions.id) AS REAL) / CAST((5) AS REAL) AS expr3
FROM questions, form_questions
WHERE form_questions.question_id = questions.id
GROUP BY questions.id, questions.text, questions.question_type_id, questions.meta, questions.max_answer_length
HAVING expr3 >= 0.75
ORDER BY COUNT(form_questions.id) DESC;
The query executes correctly with no problems in the SQLite Database Browser, but for some reason Rails is baulking at it.
The code is:
def self.find_by_commonality
Question.find_by_sql(%&
SELECT questions.id, questions.text, questions.question_type_id, questions.meta, questions.max_answer_length,
COUNT(form_questions.id) AS expr1,
(5) AS expr2,
CAST(COUNT(form_questions.id) AS REAL) / CAST((5) AS REAL) AS expr3
FROM questions, form_questions
WHERE form_questions.question_id = questions.id
GROUP BY questions.id, questions.text, questions.question_type_id, questions.meta, questions.max_answer_length
HAVING expr3 >= 0.75
ORDER BY COUNT(form_questions.id) DESC; & % [])
end
WTF is it complaining about?