PDA

View Full Version : relational DB design question


HazMatt
September 20th, 2005, 03:02 AM
I am using rails to build a web-based game (based on a board game). I have a users table and a games table. Both of these tables will have a has_and_belongs_to_many relatioship with eachother (right?). My question is about where to store some of the game and user data.

In the users table, I have login, pw, etc. But I also want to store game wins, losses and such. Should I put that in the users table or in another table that belongs_to the user?

Similarly, in the games table I have the basic games info, but I also want to track turn history - should that be in a separate table?

thanks in advance,
-HazMatt

rob
September 20th, 2005, 05:50 PM
Both of these tables will have a has_and_belongs_to_many relatioship with eachother (right?).

I'm not sure. If that's the way you want it to be, then yes. If you do a has_and_belongs_to_many, that will mean that users can belong to games, and games can contain users.

In the users table, I have login, pw, etc. But I also want to store game wins, losses and such. Should I put that in the users table or in another table that belongs_to the user?

I would put them in the users table. If they got too much, I would make a seperate table like user_profiles and tie it in with a user_id to keep things more OO and organized.

Similarly, in the games table I have the basic games info, but I also want to track turn history - should that be in a separate table?

This probably will have to go in another table. Like "turns" with a user_id game_id, etc.

bluetechnx
September 20th, 2005, 10:36 PM
if you track turn history, you could also just as easily track game history by tieing a gameID with the turn history and be able to playback older games...

HazMatt
September 21st, 2005, 11:35 AM
if you track turn history, you could also just as easily track game history by tieing a gameID with the turn history and be able to playback older games...

That's one of the things I want to do (as long as it doesn't take up too much disk space ;) ). So it sounds like I need at least one more table for game histories/turns.

Thanks for the tips!