Back

500 server error when creating a document in a collection that has relationship

  • 0
  • Self Hosted
Sam K
1 May, 2024, 20:20

I have a collection that has a relationship with 2 other collections. When I create a document from Appwrite console it works fine and it create the document. When I try to add a document from node-appwrite I get a 500 Error

I have to import around 6000 records.

appwrite version: 1.5.5 node-appwrite version: 12.0.1

Code to create the relationships:

TypeScript
await database.createRelationshipAttribute(
  "dbID",
  "collectionID",
  "663019ab000e3905b278",
  "manyToOne",
  true,
  "presupuestos",
  "cliente",
  "setNull"
);
TL;DR
Developers are experiencing a 500 server error when creating a document in a collection with relationships using `node-appwrite`. The issue seems to be related to creating relationships. They are using Appwrite version 1.5.5 and node-appwrite version 12.0.1. The code snippet for creating the relationships is provided. The developers have 9 collections in total.
Steven
1 May, 2024, 20:40

What's the schema of all your collections and the payload when creating the document?

Sam K
1 May, 2024, 20:53

discord is not allowing me to paste all of my collections in here, there are 9 collections. how I can show you the collections?

Steven
1 May, 2024, 20:53

You can. It'll upload as a file

Sam K
1 May, 2024, 20:54
Sam K
1 May, 2024, 20:54

clientes collection has 2600 documentos more or less

Sam K
1 May, 2024, 20:55

code to create the document

TypeScript
await database.createDocument(
          databaseId,
          collectionPresupuestos,
          contrato.id,
          {
            cliente: presupuesto.cliente_id,
            nombre_apellidos: presupuesto.nombre_apellidos,
            telefono: presupuesto.telefono,
            email: presupuesto.email,
            servicio_contratado: presupuesto.servicio_contratado,
            direccion: presupuesto.direccion,
            localidad_id: presupuesto.localidad_id,
            codigo_postal: presupuesto.codigo_postal,
            pisos: presupuesto.pisos,
            locales: presupuesto.locales,
            parking: presupuesto.parking,
            escaleras: presupuesto.escaleras,
            precio_presupuesto: presupuesto.precio_presupuesto,
            cliente_id: presupuesto.cliente_id,
            contrato_id: presupuesto.contrato_id,
            created_at: presupuesto.created_at,
            updated_at: presupuesto.updated_at,
          },
          [
            Permission.read(Role.user(presupuesto.cliente_id)),
            Permission.update(Role.user(presupuesto.cliente_id)),
          ]
        );
Sam K
1 May, 2024, 20:57

payload:

TypeScript
"presupuesto": {
          "nombre_apellidos": "some name",
          "telefono": "666666666",
          "email": "test@test",
          "servicio_contratado": "ite",
          "direccion": "some adress",
          "localidad_id": "{\"id\":\"328\",\"nombre\":\"Hospitalet de Llobregat, l'\",\"comarca_id\":\"13\"}",
          "codigo_postal": "12345",
          "pisos": 14,
          "locales": 0,
          "parking": "No",
          "escaleras": "izquiera-derecha",
          "precio_presupuesto": [
            "{\"gastos_desplazamiento\":3000,\"gastos_servicio\":65000,\"gastos_parking\":0,\"gastos_tramitacion\":2500,\"total\":77500,\"total_con_iva\":93775,\"num_visitas\":1,\"num_entidades\":14,\"precio_hora_tecnico\":3500}"
          ],
          "cliente_id": "1",
          "contrato_id": "3",
          "created_at": "2018-12-27T16:11:05.000Z",
          "updated_at": "2019-01-24T17:23:34.000Z"
        },
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