I have a query:
@profiles = Profile.where('whatami LIKE ? AND expectedsalaray <= ?', '%' + @job.title + '%', @job.salary)
Profiles is associated with another model called cities profile.cites
How can i check this associated model in the where statement ?
so something like:
Profile.where('profiles.city LIKE ?', @job.city)
Here are my associations:
class City < ActiveRecord::Base
has_and_belongs_to_many :profiles
end
class Profile < ActiveRecord::Base
has_and_belongs_to_many :cities
end
belongs_tocity?has_one,has_many,belongs_to.has_and_belongs_to_manyis the correct association for what you are trying to accomplish. I also don't know anything except what you've posted so I might be missing something. Do you have a table calledcities_profilesthat hascity_idandprofile_id? That's usually required for this type of relationship. guides.rubyonrails.org/…