Rails 中的预约时间表

发布于 2024-10-22 19:20:04 字数 1022 浏览 4 评论 0原文

我正在阅读 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾其所爱 2024-10-29 19:20:04

首先,我将可用约会重命名为可用性。

为每 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文