I have two classes with a one-to-many relationship, and want to find all A records that don't have any B records. I can't seem to make a B.find(:all, :conditions => "blah") work because the foreign key is in A. Any help would be appreciated...
This is essentially what I have: class A < ActiveRecord::Base has_many :B end class B < ActiveRecord::Base belongs_to :A end Am I going to have to do a :join to make this work with one sql statement? (Just to move on I wrote the following, but I know it is the wrong way to do it, just including so you can see the result I want to achieve.. ) def self.no_B ret = Array.new self.find(:all, :include => :B ).each do |a| ret << a if a.B.empty? end ret end -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.