如何使用纯activerecord(rails)执行此sql

时间:2011-04-11 04:15:26

标签: sql ruby-on-rails activerecord

我无法弄清楚如何使用活动记录来管理它。我知道它不处理外连接...

SQL:

SELECT * FROM people 
LEFT OUTER JOIN responses 
ON people.id = responses.person_id 
WHERE responses.person_id is NULL;

模型:

Person
id
has_many :responses

Response
id
belongs_to :person

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

named_scope :without_responses, :include    => :responses, 
                                :conditions => "responses.id IS NULL"