user1555112
user1555112

Reputation: 1987

CakePHP Database Structure for game with 2 and more players

I have to create a DB for a game and for the active games I need to save 2 user id's from the users table.

Normally I would use the field user_id in my activegames table to have the reference, but how do I do this with 2 users the same time? Like user_id1 and user_id2?

Keeping the CakePHP database structure along the convention?

Same question regarding the selected weapons for an active game. Just one would be weapon_id but the player can select up to 4 of them? weapon_id1, weapon_id2, weapon_id3, weapon_id4?

What is here best practice?

I look forward to your answers! Kind regards!

Upvotes: 0

Views: 102

Answers (1)

ToBe
ToBe

Reputation: 2681

You are thinking in 1-1 relations. Try 1-n relations. A "link" table that contains two columns. First is game_id, second is player_id.

This table can have any number of rows for one game. Thus no specific number of players.

player table

id    name
1     John Doe 
2     jane Doe

game table

id    title
1     A special game

game_players relation table

game_id   player_id
1         1
1         2

You can do the same with weapons (or anything else)

Upvotes: 2

Related Questions