#[Solved] 500 server error when creating a document in a collection that has relationship

27 messages · Page 1 of 1 (latest)

tranquil owl
#

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:

await database.createRelationshipAttribute(
  "dbID",
  "collectionID",
  "663019ab000e3905b278",
  "manyToOne",
  true,
  "presupuestos",
  "cliente",
  "setNull"
);
empty lava
tranquil owl
#

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

tranquil owl
#

clientes collection has 2600 documentos more or less

#

code to create the document

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)),
          ]
        );
#

payload:

"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"
        },
empty lava
# tranquil owl payload: ```js "presupuesto": { "nombre_apellidos": "some name", ...

Clientele is many to one which means it should be an array but you're passing a single id

{

        "key": "cliente",
        "type": "relationship",
        "status": "available",
        "error": "",
        "required": false,
        "array": false,
        "relatedCollection": "65d8e208004073771bcd",
        "relationType": "manyToOne",
        "twoWay": true,
        "twoWayKey": "presupuestos",
        "onDelete": "setNull",
        "side": "parent"
      }
tranquil owl
#

in the console show item only allows to select one

empty lava
tranquil owl
#

create a presupuesto document from the console works

#

I created one manually

empty lava
empty lava
tranquil owl
#

should I try to edit it?

empty lava
tranquil owl
#

here the edit screen

empty lava
#

Click add item

#

Can you add multiple?

tranquil owl
#

no it's just one

#

i will record my screen

empty lava
tranquil owl
#

you're a life saver appwritehero

#

this silly mistake took me 5h already 😂