问题描述
我要通过铁轨协会教程 http://guides.rubyonrails.org/association_basics.html
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
我应该怎样做一个模型,的has_many
预约与医师协会
例如:
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)在DB或<$ ...我怎么能存储信息C $ C> Availableappointment 模式
推荐答案
首先,我会重新命名Availableappointment情况而定。
First, I would rename Availableappointment to Availability.
创建可用性的实例为各30分钟计时插槽。您可以pre-填充它的医师编程,或医师增加了他们自己的管理部分。你需要这种观点的医生看到他的可预约无论哪种方式,因为可用性实例是唯一的每一个医生,和医生可以随时删除/重增加可用性。
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.
这篇关于在Rails的预约时间表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!