2011-04-11 46 views
0

我無法弄清楚如何純粹用活動記錄進行管理。我的理解是不處理外部聯接...如何使用純活動記錄(rails)執行此sql

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
named_scope :without_responses, :include => :responses, 
           :conditions => "responses.id IS NULL" 
+1

:without_responses可能是一個更好的名字;) – 2011-04-11 04:29:12

+0

哇。我的生活真的得到了豐富,現在我對積極記錄有了更多的信心。感謝這! – 2011-04-11 04:54:43