Back

[SOLVED] the cloud document creation doesn't register my relationships inside it

  • 0
  • Databases
  • Web
  • Cloud
Rovar2000
30 Nov, 2023, 18:14

Yeah i just found out the problem is with the relationships if they have the same items in them it will not create another order it will replace the order that has been created, can u suggest me anyways to fix this?

TL;DR
The user was experiencing an issue where the cloud document creation was not registering their relationships. They found a solution by using a many-to-many relationship instead of a one-to-many relationship. The issue was related to the relationship attributes having the same items, which caused the order to be replaced instead of creating a new one. The solution was to ensure that the relationships had unique items.
Drake
30 Nov, 2023, 18:16

What are the relationship attributes and what are the relationship types?

Rovar2000
30 Nov, 2023, 18:18

The orders have a relation of one to many to items and one to one to address, and the itemBlocker has a one to one relation to order and item

Rovar2000
30 Nov, 2023, 18:19

Should i send a picture of the collection attributes?

Drake
30 Nov, 2023, 18:19

it will replace the order that has been created

Also, what do you mean by this?

Drake
30 Nov, 2023, 18:20

orders have a relation of one to many to items

two way?

Rovar2000
30 Nov, 2023, 18:20

One way

Rovar2000
30 Nov, 2023, 18:22

Well I’m the first time seeing this but when i createDocument in orderResult for the second run it will throw that error. Document with that ID already exists. Like it’s creating a document

Drake
30 Nov, 2023, 18:23

do you have any unique indexes?

Rovar2000
30 Nov, 2023, 18:24

No I don’t.

Drake
30 Nov, 2023, 18:31

I just tried to do something like:

TypeScript
const orderResult = await database.createDocument("654b2f6a8af9b2ed391f", "6564217c78122dc22f6f", ID.unique(), orderRequest);

and it worked fine...

What API call exactly is failing?

Rovar2000
30 Nov, 2023, 18:43

Does it have a relation in it?

Rovar2000
30 Nov, 2023, 18:46
TypeScript
    try {
      const result = await Appwrite.functions.createExecution(
        "6566e3017ed5ff75b429",
        JSON.stringify(order),
        false,
        "/",
        "POST"
      );

      console.log("Executed");
      console.log(result);
    } catch (e) {
      console.log(e);
      throw e;
    }
  }
Rovar2000
30 Nov, 2023, 18:46

i'm calling this function

Rovar2000
30 Nov, 2023, 18:47
TypeScript
    id?: string | null;
    userId: string;
    items: RequestSelectedItems[];
}

interface RequestSelectedItems{
    itemId: string;
    quantity: number;
}```
Rovar2000
30 Nov, 2023, 18:47

this is the model of order i'm sending

Rovar2000
30 Nov, 2023, 19:13

example like this i just created an order with two items inside it, then created another order with the same two item inside it it just stole the items inside it from the previoues order.

Drake
30 Nov, 2023, 19:19

ohhhhh actually, i was able to reproduce...

Drake
30 Nov, 2023, 19:21

soo i think it's because it's a one to many relationship. Regardless of it being only 1 way, an item can only be linked to 1 order. You may need to use a many to many relationship

Rovar2000
30 Nov, 2023, 19:23

Yesss thank you so much, it fixed it . But is this a problem with appwrite or just how sql works?

Drake
30 Nov, 2023, 19:23

I think it's behaving as designed

Rovar2000
30 Nov, 2023, 19:27

Thank you so much

Guille
1 Dec, 2023, 12:30

[SOLVED] the cloud document creation doesn't register my relationships inside it

Biswajitchanda
25 Dec, 2023, 12:08

internal server when i am trying to create a new document async addProduct(prodData) { try { return await this.databases.createDocument( conf.appwriteDatabaseId, conf.appwriteCollectionId, ID.unique(), prodData ); } catch (error) { console.log("databaeService::addproduct::error: " + error); } }

Raja
25 Dec, 2023, 14:59

check permissions for related collections

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