Skip to content
Back

Bug in relational table

  • 0
  • 2
  • Self Hosted
  • Databases
  • Web
  • Cloud
ccl
8 Nov, 2025, 18:45

I potential found a bug or is there something I am missing?

I created 2 tables. User and Coins User has a one to one relation to Coins When attempting to create a entry in User with the relational object for Coins while the creation of the User entry throws an error the Coin object is still created.

I expect if the User row cant be created, that also the Coin row wont be created.

TL;DR
When creating a user with reference to coins, ensure proper error handling is in place for each operation to avoid rollback issues. The bug may occur due to performing all actions within a single `createRow` operation. For a solution, create coins record first, then create the user with the coins reference. If there's an error (userError), rollback and delete the coins while handling the error.
9 Nov, 2025, 03:46

You can try doing this:

  1. Create coins record first
  2. After that, create user with reference to the coins
  3. If error (userError), rollback & delete the coins
TypeScript
try {
  this.logger.log(`Creating new user ${data.providerId} in the database.`);
  
  const coinsRow = await this.database.tables.createRow({
    tableId: this.database.tablesConfig.coins,
    databaseId: this.database.databaseId,
    data: {
      balance: 200,
    },
  });

  try {
    await this.database.tables.createRow({
      tableId: this.database.tablesConfig.user,
      databaseId: this.database.databaseId,
      data: {
        $id: data.providerId,
        name: data.username,
        displayName: data.displayName,
        coins: coinsRow.$id,
      },
      rowid: data.providerId,
    });
  } catch (userError) {
    await this.database.tables.deleteRow({
      tableId: this.database.tablesConfig.coins,
      databaseId: this.database.databaseId,
      rowid: coinsRow.$id,
    });
    throw userError;
  }
} catch (error) {
  this.logger.error(
    `Error creating user ${data.providerId}: ${error.message}`,
  );
}
9 Nov, 2025, 03:49

And the error you are encountering, might be coming because you're doing it all within single createRow operation without proper error handling

9 Nov, 2025, 10:55

Ended up doing this even tho it removes the design for relations. Thats most likely still a bug

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