0
假設我有這些模型:Physician
有許多Patients
到Appointments
。如何在連接模型中編寫「範圍」?
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
end
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
end
我想寫一個範圍或類似的東西,以便我可以找到一個給定的醫師的任命的患者被確認。
什麼是最習慣的方式來做到這一點?