Back

[SOLVED] looking some help in relationship

  • 0
  • Databases
  • Web
ddet2022
21 Jun, 2023, 19:59

I am building an e-commerce application using Angular, I am trying create relationship between userProfiles and Orders collection. I have created the relationship in the Appwrite console.

My problem is, when i include the userId, into the Orders collection, its throwing error saying Invalid document structure.

async createOrder() { try {

TypeScript
  let datas = this.cartItems;
 let userId = this.storageService.getUserId();
 let data:any = [];
 datas.forEach ((el:any) => {
   data.push(JSON.stringify(el))
 } )

await this.databases.createDocument(
  environment.databaseId,
  'Orders',
  ID.unique(),
  {
    OrderItems: data,
    userProfiles: userId
  }

); console.log('Order was created successfully'); } catch(e) { console.log(e);} }

TL;DR
The user was experiencing an issue with creating a relationship between the userProfiles and Orders collection in their e-commerce application. They were getting an "Invalid document structure" error when including the userId in the Orders collection. The solution was to add await/async to their code to resolve a 'zone_symbol_error' and then pass the correct attribute key for userProfiles when creating the document.
Drake
21 Jun, 2023, 20:41

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.

Drake
21 Jun, 2023, 20:42

what typeo f attribute is userProfiles?

ddet2022
21 Jun, 2023, 22:17

its relationship

Drake
21 Jun, 2023, 22:18

sorry i was asking for more details about it

ddet2022
21 Jun, 2023, 22:19
ddet2022
21 Jun, 2023, 22:20

what should i use for attribute key? i am using the default value shown during the attribute creation

Drake
21 Jun, 2023, 22:22

whatever you want

ddet2022
21 Jun, 2023, 22:24

await this.databases.createDocument( environment.databaseId, 'Orders', ID.unique(), { OrderItems: data, userProfiles: userId } );

ddet2022
21 Jun, 2023, 22:25

am i doing correct?

Drake
21 Jun, 2023, 22:26

again, it's best to wrap multi line code with 3 backticks

Drake
21 Jun, 2023, 22:27

can you share the details of the orders attribute?

ddet2022
21 Jun, 2023, 22:27
Drake
21 Jun, 2023, 22:30

the attribute not the collection

Drake
21 Jun, 2023, 22:30

and can you share the exact error message please?

ddet2022
21 Jun, 2023, 22:32
ddet2022
21 Jun, 2023, 22:33
Drake
21 Jun, 2023, 22:34

that's weird...it says your passing __zone_symbol__state

Drake
21 Jun, 2023, 22:34

is this being executed client side?

ddet2022
21 Jun, 2023, 22:34

yes

ddet2022
21 Jun, 2023, 22:34

on browser

Drake
21 Jun, 2023, 22:35

can you open the browser dev tools, switch to the network logs, look for the POST request for this create document API call, and share the request body?

ddet2022
21 Jun, 2023, 22:55

sorry, i have added await / async the zone_symbol_error gone away

ddet2022
21 Jun, 2023, 22:56

its working now

Drake
22 Jun, 2023, 00:31

[SOLVED] looking some help in 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