Is it possible to write the following query in Rail's ActiveRecord format? I've tried a billion different ways with arel but can't get the same results.
SELECT topic_id, count(*) as total
FROM questions_topics
WHERE question_id IN (
SELECT id
FROM questions
WHERE user_id = 1000
UNION ALL
SELECT questions.id
FROM questions JOIN answers ON (questions.id = answers.question_id)
WHERE answers.user_id = 1000
)
GROUP BY topic_id
ORDER BY total DESC;