Here’s the setup:
class Person <<ActiveRecord::Base
has_one :address, :as=>:addressable
end
how would I find all persons who do NOT have an address without using
only the database? (i.e. Person.find(:all).find_all{|person|
person.address.nil?} doesn’t cut it)
Starr T. wrote:
Here’s the setup:
class Person <<ActiveRecord::Base
has_one :address, :as=>:addressable
end
oops let me try that last paragraph again
How would I find all persons who do NOT have an address using
only the database? (i.e. Person.find(:all).find_all{|person|
person.address.nil?} doesn’t cut it)
On 5 Feb 2008, at 02:33, Starr T. wrote:
How would I find all persons who do NOT have an address using
only the database? (i.e. Person.find(:all).find_all{|person|
person.address.nil?} doesn’t cut it)
Something like ?
Person.find :all, :joins => “LEFT OUTER JOIN addresses ON
addressable_id = people.id AND addressable_type = ‘Person’”,
:conditions => ‘addresses.id IS NULL’