Topic: A better way to query across my joined table

I have a database setup such that every person is a person_type.  Then the person_type may or may not be an organisation (determined by a boolean string in the table).

I want to return all people that are not a person_type defined as an organisation.

My ugly code in the controller currently works, however it looks like this:

str_org_ids = ''
@person_types = PersonType.find(:all, :conditions => "organisation = 1")
@person_types.each do | person_type |
  str_org_ids += person_type.id.to_s + ", "
end
str_org_ids = str_org_ids[0..(str_org_ids.length-3)]
@people = Person.find(:all , :conditions => "person_type_id <> " + str_org_ids)

I'm sure it can be refactored, does anyone have any suggestions?

Warm regards,
Ian

Re: A better way to query across my joined table

Hi

what about this:

@people = Person.find(:all, :include => :person_types, :conditions => "person_types.organisation != 1")

Hope that helps :-)

Re: A better way to query across my joined table

Perfect, thank you so much.

I knew I must have been going the long way round! ;-)