
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 {
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);} }

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.

what typeo f attribute is userProfiles?

its relationship

sorry i was asking for more details about it


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

whatever you want

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

am i doing correct?

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

can you share the details of the orders attribute?


the attribute not the collection

and can you share the exact error message please?


AppwriteException: Invalid document structure: Unknown attribute: "__zone_symbol__state" at Client.<anonymous> (http://localhost:8100/default-node_modules_appwrite_dist_esm_sdk_js.js:914:17) at Generator.next (<anonymous>) at fulfilled (http://localhost:8100/default-node_modules_appwrite_dist_esm_sdk_js.js:548:24) at _ZoneDelegate.invoke (http://localhost:8100/polyfills.js:8189:158) at Object.onInvoke (http://localhost:8100/vendor.js:55707:25) at _ZoneDelegate.invoke (http://localhost:8100/polyfills.js:8189:46) at Zone.run (http://localhost:8100/polyfills.js:7972:35) at http://localhost:8100/polyfills.js:9050:28 at _ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:8216:171) at http://localhost:8100/vendor.js:55394:49

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

is this being executed client side?

yes

on browser

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?

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

its working now

[SOLVED] looking some help in relationship
Recommended threads
- Is it possible to getRow with all relati...
With the new Opt-In relationship loading, is it possible to query getRow to get all attributes and relationships and possibly even cascading relationships? I tr...
- TableDB.getRow() response does not conta...
This is for Web/React sdk 20.0.0 The row was created via `TableDB.createRow(...)` and I can see it in the console with the relationships correctly set. In the c...
- Permissions for bulk operation
Hi team, I have a question: “In the databases.createDocuments bulk API, can I set document-level permissions? If yes, how exactly should I include the permissio...
