I need to create a database for managing teams. The 2 tables im wrestling with are the meet table and the events table.
Here is the basic flow
Team A can create a new track meet which will add 1 row to the meet table with meta data for the meet such as dates, location it also has to include a list of events.
Events is a table of about 500 possible events that can be competed at during a meet. Things such as distance, type of event, male / female, age
I want during the generation of a meet for the user to be able to select which events that meet will have.
So create a new meet, complete meta data, and select (for Ex) 30 events from a list of all possible events.
Soooo my question is what table structure best supports that. I was thinking of a column in my meet table that holds and array of events.? But is there a better way to handle that.? Im using postgres and rails
This sounds like a perfect use for the Rails has_many :through association. You should have a
meet_eventsjoin table. Themeet_eventstable would have a foreign key (belongs_to)meet_idcolumn in it which points to the meet it is associated with and anevent_idcolumn in it which points to one of the available events. YourMeetmodel would usehas_many :meet_eventsandhas_many :events, :through => :meet_events. That will allow you to get the event objects associated with this meet.The
MeetEventmodel simply has twobelongs_to. One for themeetand one for theevent.Here’s a simple set of models:
Here’s an example of some data and what it is modeling:
meets
events
meet_events
This is basically modeling that
Meet 1hasEvent 1andEvent 3in it.Meet 2hasEvent 2andEvent 3. This also gives you the benefit of asking a particularEventwhat meets it is in. So for example, callingevent.meetswheneventis Event 3, it will tell you that bothMeet 1andMeet 2have that event in them.