Back

Adding documentId to relationship attribute

  • 0
  • Databases
  • Web
tinfoilht
28 Jan, 2025, 18:26

I am creating a sports app. we have leagues that we have a league_teams attribute that is a relastionship with our league_teams collection. I used this code const newTeam = await databases.updateDocument( process.env.NEXT_PUBLIC_APPWRITE_DATABASE!, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_LEAGUES!, leagueId, { leagueTeams: [ { $id: ID.unique(), name: teamName, players: players, }, ], } );

did add the new team to the relationship, but it removed all of the other teams that had relastionships with the collection.

Is there a way to add and remove 1 team at a time to the relationship in one step, or will I need to create the team in the teams colection and then add it to the relationship attribute?

TL;DR
Problem: Adding a team to a relationship attribute removes all other teams in the collection. Solution: To add and remove one team at a time to the relationship without affecting the other teams, create the team in the teams collection first and then add it to the relationship attribute.
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