Back

[Closed] Error deleting documents with relationship

  • 0
  • Self Hosted
  • Databases
Ernest
8 Dec, 2023, 15:21

Getting errors deleting documents from collection related with another Simplified Setup: 3 related collections

  • Color (attrb: name)
  • Shape (attrib: name, shapeColor[related field])
  • ShapeColor (attrib: color[FK: <one way> m-to-1 on Color on delete set null], shape[FK: <two way> m-to-1 on Shap on delete cascade]

Deleting a document from Color doesn't set the related fields in ShapeColor to null but throws an Server error. Appwrite container logs

TypeScript
2023-12-08T15:18:22.985230878Z [Error] Timestamp: 2023-12-08T15:18:22+00:00
2023-12-08T15:18:22.985262759Z [Error] Method: DELETE
2023-12-08T15:18:22.985266599Z [Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents/:documentId
2023-12-08T15:18:22.985270119Z [Error] Type: Utopia\Database\Exception
2023-12-08T15:18:22.985272879Z [Error] Message: Unknown PDO Type for object
2023-12-08T15:18:22.985275519Z [Error] File: /usr/src/code/vendor/utopia-php/database/src/Database/Adapter/MariaDB.php
2023-12-08T15:18:22.985278319Z [Error] Line: 1878

Conversly, deleting a document from ShapeColor throws Document not found exception Appwrite container logs

TypeScript
2023-12-08T16:05:44.447421368Z [Error] Method: DELETE
2023-12-08T16:05:44.447424608Z [Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents/:documentId
2023-12-08T16:05:44.447427528Z [Error] Type: Appwrite\Extend\Exception
2023-12-08T16:05:44.447430128Z [Error] Message: Document with the requested ID could not be found.
2023-12-08T16:05:44.447432808Z [Error] File: /usr/src/code/app/controllers/api/databases.php
2023-12-08T16:05:44.447435408Z [Error] Line: 3557
TL;DR
There are errors when deleting documents with relationships. Deleting a document from the 'Color' collection doesn't set the related fields in 'ShapeColor' to null and throws a server error. On the other hand, deleting a document from 'ShapeColor' throws a 'Document not found' exception. No solution is provided in the support thread.
Ernest
8 Dec, 2023, 17:54

Update: There are multiple issues with deleting documents with relationships in general. Here are some relevant issues: https://github.com/appwrite/appwrite/issues/7170 https://github.com/appwrite/appwrite/issues/5850

I know relationships are experimental but I allowed myself to be temptep by the dark side (normalisation). I'll be creating relationships manually.

Ernest
8 Dec, 2023, 17:58

[Closed] Error deleting documents with relationship

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