1

I’m building a web app using Rails API on server side. The goal is to make a planning manager. I want my users to be able to plan ‘daily’ events, which will display at some specific weekdays, with some specific member in charge.

Here’s a quick example about what data should look like :

event_name
- Monday with UserC
- Wednesday with UserA

Code

I have a collection of events, which looks like following :

event.rb

class Event < ApplicationRecord
  enum event_type: { punctual: 0, days_of_week: 1, rotative: 2 }
  validates :name, presence: true
  validates :event_type, presence: true
end

:event_type will link to a more specific table, depending on its value.

Goal

According to this, I’d like to know which is the best way to design the daily events (event_type: :days_of_week), with the following requirements :

  • assign one or multiple users per weekday
  • delete a user doesn’t delete the event. If no user is left for a weekday, it disappears from the event
  • being able to update the event by adding new members to a day, wether it was already assigned or not

I tried

I thought of two solutions, but can’t decide which one is better, or even if one of them is suitable :

  1. create a has_many relation for event_type: :days_of-week, with a daily table, in which each row contains a day id plus a list of user ids :
    Event -> has_many :daily
                - user_id
                - day_id
  1. create a has_one relation, with a daily table containing 7 columns, each for a specific weekday :
Event -> has_one :daily
                - monday = member_id
                - tuesday = member_id
                …
                - sunday = member_id

Thanks in advance for any help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.