Below code is from http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association
class CreateAppointments < ActiveRecord::Migration
def change
create_table :physicians do |t|
t.string :name
t.timestamps null: false
end
create_table :patients do |t|
t.string :name
t.timestamps null: false
end
create_table :appointments do |t|
t.belongs_to :physician, index: true
t.belongs_to :patient, index: true
t.datetime :appointment_date
t.timestamps null: false
end
end end
In the above example how do i:
1) Create/destroy a relation between a physician and patient. Do i just use:
Create: Appointment.create(physician_id, patient_id)
Destroy: (i have no clue hot to do this)
What is the correct way to do it?
2) How would i access all the appointment_date in the Appointment model for a particular patient or physician?
@course
. So although the topic is now part of@course
, and accessible through@course.topics
, there's no persistent relationship. – bo-oz