开发者

How to do this sql with pure activerecord (rails)

开发者 https://www.devze.com 2023-02-23 20:54 出处:网络
I can\'t figure out how to manage this purely with active record.I understand it doesn\'t handle outer joins...

I can't figure out how to manage this purely with active record. I understand it doesn't handle outer joins...

SQL:

SELECT * FROM people 
LEFT OUTER JOIN responses 
ON people.id = respo开发者_运维问答nses.person_id 
WHERE responses.person_id is NULL;

MODELS:

Person
id
has_many :responses

Response
id
belongs_to :person

Any suggestions?


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

精彩评论

暂无评论...
验证码 换一张
取 消