I am trying to build a model to store event information and create a sign up list for it. What is the best way to associate a sign up list? Should I serialize a column and make it store like: user1, user2, user3 or should I create a new table. If I create a new table how would I relate it to this model? There are going to be multiple events with signups.
Currently I have this for the rest of the model:
rails generate model Event title:string description:string start:datetime end:datetime location:string numberofvolunteers:integer
This is a fairly standard data modelling problem and you'd typically want to model it as a many-to-many relationship. You'll need to generate an intermediate table to join events and users. Below I've added a couple of useful attributes you might want to track - whether the invite was accepted (RSVP'd) and whether they actually attended:
rails generate model Invite user_id:integer event_id:integer accepted:boolean attended:boolean
So then you have:
class Event
has_many :invites
has_many :users, through: :invites
end
And
class User
has_many :invites
has_many :events, through: :invites
end
And you can also get fancy by filtering on accepted
and attended
to create additional relationships if you want.
The solution here is very much "The Rails Way" and should probably be your default inclination when designing the database. However, your first suggestion of just storing a list of user IDs is possible too if you don't care to ever look up which events a user attended and you want to manually check the list is unique (so the same user isn't down twice).