2010-05-13 92 views
0
class Customer < ActiveRecord::Base 
    has_one  :address, :foreign_key => "customerid" 
end 

class Address < ActiveRecord::Base 
    belongs_to :customer, :foreign_key => "customerid" 
end 

如何查找在客戶中沒有customerid地址表中的記錄?導軌通過關聯查找

在SQL我會做

select * from customer a, address b where a.customerid <> b.customerid 

回答

0

這將返回customers不具有address

Customer.find :all, 
    :conditions => 'id NOT IN (select distinct customerid from address)' 

希望我理解正確你的問題。