Rails 中的预约时间表
我正在阅读 Rails 关联教程 http://guides.rubyonrails.org/association_basics.html
我想进一步扩展这个模型以满足我的需求:
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
我应该如何制作一个与 has_many
预约与 Physician
关联的模型
例如:
class Physician < ActiveRecord::Base
has_many :appointments
has_many :availableappointments
has_many :patients, :through => :appointments
end
class Availableappointment < ActiveRecord::Base
belongs_to :physician
end
我对如何存储不同的时间感到困惑模型中的框架?假设医生的工作时间为上午 8 点至下午 3 点,每次预约时间为 30 分钟(8:30-9、9-9:30、9:30-10)...我如何将此信息存储在数据库或 可用预约
模型
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
belongs_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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我将可用约会重命名为可用性。
为每 30 分钟的时间段创建可用性实例。您可以通过编程方式为医师预先填充它,或者医师自己将其添加到管理部分。无论哪种方式,您都需要此视图让医生查看他的可用预约,因为可用性实例对于每个医生来说都是唯一的,并且医生始终可以删除/重新添加可用性。
然后,将从可视化医生可用性的视图中创建预约。当根据可用性创建约会时,删除该可用性。
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.