0

(This is for a side project/personal website)

Right now I have the activities table/model with the following columns... How would I add the specific days of the week the event is happening on? The user should be able to click days of the week from the view, if selected then the value for that day becomes true.

So I was thinking Id need a table of booleans called days of week, but how Im not quite sure how to tie it to the activites model.I was also thinking I could make 7 day boolean values in the activities table. I feel like that would be really sloppy

Activities model/ table

create_table "activities", force: :cascade do |t|
    t.text "content", null: false
    t.string "activity_name", null: false
    t.string "additional_info"
    t.bigint "user_id"
    t.string "cost", null: false
    t.string "addressLN1", null: false
    t.string "addressLN2"
    t.string "city", null: false
    t.string "state", null: false
    t.string "zip", null: false
    t.string "picture"
    t.string "capacity", null: false
    t.string "contact_number"
    t.string "contact_email", null: false
    t.datetime "start_date", null: false
    t.datetime "end_date", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["user_id", "created_at"], name: 
    "index_activities_on_user_id_and_created_at"
    t.index ["user_id"], name: "index_activities_on_user_id"
  end
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • I take it the days may not be contiguous? I.e., Start_Date might be Monday and End_Date Friday, but it wouldn't necessarily include all of the days between? What happens if the timeframe is multiple weeks and the days of the weeks are different on different weeks, is that possible? – Ben Jan 28 '19 at 22:29
  • What DB are you using? maybe instead of using 7 boolean columns you can use a json columns if you are using postresql so you can index that and make queries. Anyway, 7 columns may sound sloppy but I wouldn't discard that, you can do queries on boolean columns that can be indexed. This question may fall in te category of mostly opinion based. – arieljuod Jan 28 '19 at 23:39
  • @arieljuod im using postgres but i dont really know what indexing is so I will now look that up. 7 extra boolean columns would not be smart here (imo) because theres already over 20 columns and it might get a bit messy at times – henrietta Jan 29 '19 at 01:43
  • The number of coulmns being a problem is pretty much subjective, PostreSQL is designed to support beetween 250 and 1600 columns on a single table, your number of columns doesn't sound like a problem to me but that's subjective too. It's ok if you don't want to use 7 new columns but I'd recommend you to base your decision on real benefits and cons rather than thinking that "it might get a bit messy". – arieljuod Jan 29 '19 at 04:09
  • @arieljuod i want aware. Im working on this project with a few people and didnt want them to think Im lazy basically. I just added 7 boolean columns and that has been the easiest solution to the problem. – henrietta Jan 29 '19 at 17:39

0 Answers0