Back

[SOLVED] 2Way Relationships Databases

  • 0
  • Databases
flo<3ler
27 Sep, 2023, 07:21

Hey, I'm trying to setup a proper database structure for my basketball game data app and would like to incorporate relations to avoid duplicate data.

I'm on the free Appwrite Cloud plan, so I have one Database available.

My use case is this:

I have two different types of Collections: Player and League. A League has documents representing basketball game stats, one document per game per player. A Player has their overall points and so on, essentially only one document in this collection.

The Relation I want to introduce is in the form of linking a Player to their played games in the respective leagues.

Player can have many games Game can have 1 Player, so I selected the one-to-many relationship.

But, at least in the console, it's kinda confusing to select the attributes to use. I was trying to use leagueGames for the player collection and player for the league collection. This worked well for 1 player, but when i create the Relation in a collection for a second player, it cant create a relation attribute with the same key.

So this essentially defeats the purpose that I save data, because now I have to create ANOTHER attribute (e.g. leagueGames2) where I can select the second player.

What am I missing? I want to link different documents from a league collection to different players, is this currently possible?

Maybe I am approaching it from the wrong side, but when I try to create it from the league side, I have to choose only one collection to link.

TL;DR
The user was trying to set up a database structure for their basketball game data app. They have two collections: Player and League. The user wanted to create a relationship where a player is linked to the games they have played in the respective leagues. They were having trouble selecting the attributes to use for the relationship. They were able to create the relationship for one player, but when they tried to create it for another player, they couldn't use the same key. The user wanted to know if it was possible to link different documents from the league collection to different players. Solution: The user realized that they can introduce one collection for all players
flo<3ler
27 Sep, 2023, 07:22

When I read it again, it probably makes sense to introduce one collection for all players, as they consist of only one document each. Then this problem would solve itself...

flo<3ler
27 Sep, 2023, 07:23

so to sum it up:

collection players -> document for overall stats of each player

collection league -> document for each game and link an attribute 'player' to the corresponding player in the collection

flo<3ler
27 Sep, 2023, 07:33

Yes, this did the trick. Sorry for posting a trivial question but it helped me figure out my problem 🙂

Marking this as Solved

flo<3ler
27 Sep, 2023, 07:34

[SOLVED] 2Way Relationships Databases

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more