0
我目前有以下三種模式:通過協會查找模型
class Vacancy < ActiveRecord::Base
# Database Associations
has_many :vacancy_occupations, :foreign_key => :vacancy_id
has_many :occupations, :through => :vacancy_occupations
belongs_to :country
belongs_to :employer
# Database Validations
validates_presence_of :name, :title, :description
end
class VacancyOccupation < ActiveRecord::Base
belongs_to :vacancy, :foreign_key => :vacancy_id
belongs_to :occupation, :foreign_key => :concept_id
end
class Occupation < Concept
end
class Concept < ActiveRecord::Base
# Database Associations
has_many :labels
has_many :vacancy_occupations, :foreign_key => :concept_id
has_many :cv_occupations, :foreign_key => :concept_id
has_many :vacancies, :through => :vacancy_occupations
has_many :cvs, :through => :cv_occupations
# Database Validations
validates_presence_of :uri
validates_uniqueness_of :uri
end
我正在尋找的是選擇具有特定的職業空缺,所有的機制。目前我可以通過以下聲明得到它:
@vacancies = Vacancy.joins(:vacancy_occupations).where('vacancy_occupations.concept_id' => occupation_ids).uniq
但我想知道是否有一個更乾淨的語法來完成這項工作?一直玩的包括選項,並嘗試從不同的模型作爲出發點,但我似乎失去了絕望。
將結束我在那有一個職業聯剛結束的所有空缺,而我只是想掛一個特定職業的空缺。 – 2011-05-18 11:29:13
職業= Occupation.find(...)then,occupation.vacancies – jaydel 2011-05-18 11:39:02