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.
You can try doing this:
- Create coins record first
- After that, create user with reference to the coins
- If error (userError), rollback & delete the coins
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}`,
);
}
And the error you are encountering, might be coming because you're doing it all within single createRow operation without proper error handling
Ended up doing this even tho it removes the design for relations. Thats most likely still a bug
Recommended threads
- Error With iOS Apps
I keep getting the below errors for my flutter app. The clients are registered and have been. This wasn't an issue a few hours ago. AppwriteException: AppwriteE...
- Backup policies think im on free tier
Cant create more than one policy as im told to ugprade, when clicking upgrade im taken to the upgrade page which confirms im already on pro
- Cant get rid of "get started"
Not that important, but annoying. No matter what I do I cant get the "Get started" to go away, ive added a bunch of web platforms and its just stuck.