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)
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Starr Trader 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) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5 Feb 2008, at 02:33, Starr Trader wrote:> > Starr Trader 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)Something like ? Person.find :all, :joins => "LEFT OUTER JOIN addresses ON addressable_id = people.id AND addressable_type = ''Person''", :conditions => ''addresses.id IS NULL''> -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---