Рельсы выплевывали мне это:
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;
Запрос выполняется корректно, без проблем в браузере баз данных SQLite, но по какой-то причине Rails недоволен им.
Код:
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 на что жалуется?