我在这里有这个美味的SQL查询,我试图弄清楚如何使用他们的活动记录方法在rails中实现==> .select()。where()等...
SELECT
topics.id
FROM topics
WHERE
NOT EXISTS (
SELECT *
FROM votes
WHERE votes.topic_id = topics.id
)
答案 0 :(得分:1)
试试这个
@topics = Topic.where("not exists (SELECT * FROM votes WHERE votes.topic_id = topics.id)")