Jump to content

The ultimate community for Ruby on Rails developers.


Model Design Question - Sports League

  • Please log in to reply
No replies to this topic

#1 Jemagee



  • Members
  • 62 posts

Posted 10 April 2014 - 04:45 PM

As my first project, I'm attempting to recreate a sports league database I've built for my own use directly in MySQL - it's kind of a data warehouse thing so I think of it as good practice because there's no user logins and levels to work with just yet.


I have a question regarding one of my models versus how I do it in sequel.


Model Game

 has_many :teams through :gameteam


Model Team

 has_many  :games through :gameteam


Model GameTeam

  this model indicates which two teams (by id) played in the game (by id) and whether that team was home or away and winner/loser


Model GameStats

 this model will store all the end of game stats (by team) for each game...i.e there are two lines per game_id - one for the home and one for the away team


My question is should i create a 'complex' foreign key of GameID and TeamID or should i have it reference the auto generated id in the 'gameteam' model.


I'm not used to using auto generated keys - in general Relational database design you often wanna use a 'memorable' primary key because you're writing direct queries but I was thinking that because of the rails 'top' i could use the GameTeam_id and it might save time?


I hope this questions makes sense

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users