开发者

Appointment Time schedule in Rails

I am going through the rails association tutorial http://guides.rubyonrails.org/association_basics.html

I want to extend this model further to fit my needs:

class Physician < ActiveRecord::Base
  has_many :appointments
  has_many :patients, :through => :appointments
end

class Appointment < ActiveRecord::Base
  belongs_to :physician
  belo开发者_如何学Cngs_to :patient
end

class Patient < ActiveRecord::Base
  has_many :appointments
  has_many :physicians, :through => :appointments
end

How should I make a model that has_many appointments association with Physician

For example:

class Physician < ActiveRecord::Base
  has_many :appointments
  has_many :availableappointments
  has_many :patients, :through => :appointments
end

class Availableappointment < ActiveRecord::Base
  belongs_to :physician
end

I am stumped on how to store different time frames in the model? Lets say a physician is available from 8AM - 3PM with each appointment being 30 minutes (8:30-9, 9-9:30, 9:30-10)...how can I store this information in the DB or Availableappointment model


First, I would rename Availableappointment to Availability.

Create instances of Availability for each 30 minute time slot. You can either pre-populate it for the Physician programmatically, or the Physician adds them himself in an admin section. You need this view for the Physician to see his Available appointments either way, because the Availability instances are unique to each Physician, and Physician can always remove/re-add Availability.

Then appointments will be created from a view which visualizes the Physician availabilities. When Appointment is created based off an Availability, remove the availability.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜