Rails and stackoverflow beginner here so please pardon me for any mistakes.
I am developing an appointment booking system between doctors and patients. Now, the flow goes like this A doctor will create its available time slots and the patients can see the available time slots of a particular doctor and can book the time slot.
class Doctor < ApplicationRecord
has_many :availabilities
has_many :appointments
has_many :patients, through: :appointments
end
class Availibilities < ApplicationRecord
#table columns: id | start_date | start_time | end_date | end_time | slot_taken(boolean)
belongs_to :doctor
end
class Patient < ApplicationRecord
has_many :appointments
has_many :doctors, through:appointments
end
class Appointment < ApplicationRecord
belongs_to :patient
belongs_to :doctor
end
Now, how do I connect the patient to the availabilities model? How can I make a relationship which will fetch me which doctor's slots the patient has booked? Any other method through which I can achieve the above relationships/ functionality?
Also correct me if the above relationships are wrong.