我正在学习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),...how我可以将此信息存储在DB或Availableappointment
模型中吗
发布于 2015-01-03 04:42:22
首先,我会将Availableappointment重命名为Availability。
为每个30分钟的时间段创建可用性实例。您可以通过编程方式为医生预先填充它,也可以由医生自己在管理部分中添加它们。无论哪种方式,您都需要这个视图让医生查看他的可用预约,因为可用性实例对于每个医生都是唯一的,并且医生总是可以删除/重新添加可用性。
然后,将从可视化医生可用性的视图中创建约会。基于可用性创建约会时,删除可用性。
https://stackoverflow.com/questions/5330762
复制相似问题