سؤال

I have Player entity and Game entity.

One player to many games relationships.

So Player has position attribute

  • offense
  • defense

When I create player and add this player to the team I set the position offense or defense.

But for the different game the player can have offense position or defense position and this position can't be overwritten for the player in the team. So if I created player number 10 with position offense it can't be modified, because each player in the team have appropriated position. But for the game we can set new position for the player if we want. So suppose for the game with id = 10 I have player with id = 7 which has position = offense, but I want this player with player id = 7 have position defense for the game with id = 12.

For the game with id 10 we have position offense the player

Game
id = 10
player.id = 7
player.position = offense

For the game with id 12 we have position defense for the same player

Game
id = 12
player.id = 7
player.position = defense

So As you can see I use different game but use the same player and if I will set new parameter to player.position I will override previous value that's no good because it will store just latest position and when I will fetch players I will have players that have last modified positions.

I suppose make this is in next way:

I have player entities, so to make different position for each player in cornet game, I have to copy this entity and set the position I want, but the problem there that's I will duplicate players and it is not good, because the better way use the same player (the one player) for each game and have another object that will save the parameters of the concrete game for concrete player.

Does it make sense? Or maybe I need another approach to solve this issue. In any case I think the best way to have not duplicated player.

هل كانت مفيدة؟

المحلول

My solution for these case should be something like this

Game
id = 10
player.id = 7
playerSkill.position = offense
playerSkill.idPlayer = 7 
playerSkill.speed = 9

Player
id
name
nationality
...

PlayerSkill
position
idPlayer
speed
....

So you will have for each game a player with his skills, and you can create new games for the same player and create new skills

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top