2010-05-13 70 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)' 

希望我理解正确你的问题。