Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple One-to-Many Relationships with the same Type #1301

Open
pffigueiredo opened this issue Oct 12, 2024 · 0 comments
Open

Comments

@pffigueiredo
Copy link

Description

As of right now, .exo schemas don't allow to have more than one "one to many" relations towards the same Type.

e.g.

 type Game {
    @pk id: Int = autoIncrement()
    player1: Player
    player2: Player
  }

  type Player {
    @pk id: Int = autoIncrement()
    name: String
    games: Set<Game>
  }

In the example described above, there is no distinction between player1 or player2 games as they are completely coupled to each other, however, they reference different rows and make sense for this specific domain.

Possible workaround

One potential workaround is to model the relationship as a many-to-many relation, accepting that each Game will always have exactly 2 players (player1 and player2). This could look something like:

  type Game {
    @pk id: Int = autoIncrement()
    playerGames: Set<PlayerGame>
  }

  type PlayerGame {
    @pk id: Int = autoIncrement()
    player: Player
    game: Game
  }

  type Player {
    @pk id: Int = autoIncrement()
    name: String
    playerGames: Set<PlayerGame>
  }

While this approach works, it imposes additional complexity and doesn’t fully capture the semantics of having two distinct Player roles in the Game type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant