I have a question concerning active record association, referring to this part of the rails documentation:
http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association
if we have three models:
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
The documentation says that the collection of join models can be managed via the api this way:
physician.patients = patients
but what if the appointment model, like in the linked example, has a field called appointment_date and I want to create a new appointment given the Physician and the Patient at a specific date? The following code will create a record in the appointment table, but how to populate the appointment_date too in the third step?
physician = Physician.first
patient = Patients.first
physician.patients << patient
does something like this exists?
physician.patients.create( :patient => patient, 'appointment.appointment_time' => appointment_time )