Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to model "appointments" in Rails?
    primarykey
    data
    text
    <p>Here's the scenario I'm facing:</p> <p>An appointment could be scheduled for:</p> <ol> <li>today</li> <li>some time during the week</li> <li>on a specific date</li> </ol> <p>So, the attributes can be different for each "type" of appointment.</p> <p>I was thinking of these models and using it with STI, but I'm not sure if I'm on the right track:</p> <pre><code>class Appointment &lt; ActiveRecord::Base class TodayAppointment &lt; Appointment class WeekAppointment &lt; Appointment class SpecificDateAppointment &lt; Appointment </code></pre> <p>Table:</p> <pre><code>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" </code></pre> <p>What's the best way to model this?</p> <p>Is this a good candidate for Single Table Inheritance?</p> <p><strong>UPDATE</strong></p> <p>Thanks @Mike, @SpyrosP for the help so far. I've come up with the options that I have below.</p> <p>These are the "views" of the database tables and what they would look like.</p> <p>Which one seems most appropriate?</p> <pre><code>------------------------------------------------------------------------ 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 | ------------------------------------------------------------------------ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload