如何在Ruby on Rails中实现此SQL查询

时间:2017-03-30 06:44:20

标签: mysql sql ruby-on-rails activerecord

我在这里有这个美味的SQL查询,我试图弄清楚如何使用他们的活动记录方法在rails中实现==> .select()。where()等...

SELECT topics.id FROM topics WHERE NOT EXISTS ( SELECT * FROM votes WHERE votes.topic_id = topics.id )

1 个答案:

答案 0 :(得分:1)

试试这个

@topics = Topic.where("not exists (SELECT * FROM votes WHERE votes.topic_id = topics.id)")