Find across multiple models

I have a search form that provides a param to a find condition. I have a projects model with multiple joins to other models:

has_many :accomplishments   has_many :cooperatorships   has_many :sponsorships   has_many :cooperators, :through => :cooperatorships   has_many :sponsors, :through => :sponsorships

My search when setup like this works:

def self.search(search)     if search       find(:all, :conditions => ['projects.name LIKE ?             OR projects.description LIKE ?             OR projects.leadName LIKE ?             OR sponsors.name LIKE ?',             "%#{search}%",             "%#{search}%",             "%#{search}%",             "%#{search}%"],             :include => :sponsors           )     else       scoped     end   end

If I attempt to add another include like:

:include => {:sponsors, :cooperators}

ActiveRecord reports an error that it can't find the relation and perhaps I've spelled it incorrectly.

I can switch out :sponsors for :cooperators and change the query and it finds the relation just fine.

Is it possible to do multiple joins or "includes" in this way?

Thanks, -Jim

I have a search form that provides a param to a find condition. I have a projects model with multiple joins to other models:

has_many :accomplishments has_many :cooperatorships has_many :sponsorships has_many :cooperators, :through => :cooperatorships has_many :sponsors, :through => :sponsorships

My search when setup like this works:

def self.search(search)    if search      find(:all, :conditions => ['projects.name LIKE ?            OR projects.description LIKE ?            OR projects.leadName LIKE ?            OR sponsors.name LIKE ?',            "%#{search}%",            "%#{search}%",            "%#{search}%",            "%#{search}%"],            :include => :sponsors          )    else      scoped    end end

If I attempt to add another include like:

:include => {:sponsors, :cooperators}

:include => [:sponsors, :cooperators]

You want an array, not a hash.

Philip Hallstrom wrote in post #996237: