1

I´m creating a project in jhipster and I need to access to this metrics and structure:

Structure:

Of the players we want to save:

  • Nickname (unique) can only be formed by: letters, numbers and underscore.
  • Name
  • Surname
  • Date of birth

Secondly, we must create the necessary structure to host the games. For each game played we want to save:

  • Player who has won the game
  • Player who has lost the game
  • Number of points of the winner
  • Game played

Metrics:

  • For a specific player, whose nickname must be provided, list of games won.
  • For a given player, number of games won.
  • List of players who have won playing a given game.

My problem is that the list of players to match with the list of winner and losers and right now this is not happening. The is a list of players with nickname etc and a different one not related of winners and losers.

How can I create the relationship in this case?

This is my code so far in JDL-Studio. It doesn´t work.

entity Player {
    nickname String unique pattern(/[a-zA-Z0-9_]+/),
    name String,
    surname String,
    dateOfBirth LocalDate
}

entity Game {
    winnerPoints Integer,
    loser String,
    winner String,
    game String
}

relationship ManyToMany {
    Game{player(nickname)} to Player{game}
}

Relationship Jhipster

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
  • Your question is not clear enough, please edit it to better describe your problem, what does not work. – Gaël Marziou Apr 28 '22 at 13:16
  • Thanks for the advice, I just done it: My problem is that the list of players to match with the list of winner and losers and right now this is not happening. The is a list of players with nickname etc and a different one not related of winners and losers. – FRANCISCO JAVIER SEGURA CRUZ Apr 28 '22 at 17:49

2 Answers2

1

Winner and loser should not be strings, they should be 2 relationships to Player. Also it seems strange that Game entity has a game field, either the entity is badly named or it's the field.

entity Player {
    nickname String unique pattern(/[a-zA-Z0-9_]+/),
    name String,
    surname String,
    dateOfBirth LocalDate
}

entity Game {
    winnerPoints Integer,
    game String
}

relationship ManyToOne {
    Game{winner(nickname)} to Player,
    Game{loser(nickname)} to Player
}

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
  • It looks like it´s working man, thanks man !!!! A few doubts I have: - Something weird happend, it creates the columns winner and loser but they are empty. When I create a new game to add it to the list it shows me the options to add a nickname inside the winner and loser wich tells me that works but, is there a way to fill the columns winner and loser up with the nicknames randomly? – FRANCISCO JAVIER SEGURA CRUZ Apr 30 '22 at 06:57
  • If it's working then please accept my answer. I'm not sure I understand your question, if it's about loading demo data then have a look at src/main/resources/config/liquibase/fake-data – Gaël Marziou Apr 30 '22 at 08:04
0

Regarding the last question, try making the relationship required:

relationship ManyToOne {
    Game{winner(nickname) required} to Player,
    Game{loser(nickname) required} to Player
}
jelharou
  • 86
  • 5