Here is the scenario I am facing:
An appointment may be planned for:
- Today
- some time during the week
- on a specific date
Thus, attributes can be different for each destination “type”.
I thought about these models and used it with STI, but I'm not sure I'm on the right track:
class Appointment < ActiveRecord::Base
class TodayAppointment < Appointment
class WeekAppointment < Appointment
class SpecificDateAppointment < Appointment
Table:
string, Type #type of the appointment (TodayAppointment, WeekAppointment...)
datetime, When #data used when type field is "SpecificDateAppointment"
string, Something #used when type field is "TodayAppointment"
What is the best way to simulate this?
Is this a good candidate for one-dimensional inheritance?
UPDATE
Thanks @Mike, @SpyrosP for helping so far. I came up with the options that I have below.
These are the “views” of the database tables and how they look.
Which one is most suitable?
------------------------------------------------------------------------
Option A--(Polymorphic Association)
------------------------------------------------------------------------
|patients | day_appointments | week_appointments
| appointment_type | data | data
| appointment_id | |
------------------------------------------------------------------------
Option B--(Child references parent) (What is this pattern called?)
------------------------------------------------------------------------
|patients | day_appointments | week_appointments
| | patient_id | patient_id
------------------------------------------------------------------------
Option C--(Polymorphic Association + Single Table Inheritance of appointments)
------------------------------------------------------------------------
|patients | appointments |
| appointment_type | type |
| appointment_id | day_data |
| | week_data |
------------------------------------------------------------------------
Option D--(Child references parent + Single Table Inheritance of appointments)
------------------------------------------------------------------------
|patients | appointments |
| | type |
| | day_data |
| | patient_id |
------------------------------------------------------------------------
Zabba source
share