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
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...
- What Query's are valid for GetDocument?
Documentation shows that Queries are valid here, but doesn't explain which queries are valid. At first I presumed this to be a bug, but before creating a githu...
- Custom emails
What happen if I use a third party email provider to customize my emails and my plan run out of emails/month? Appwrite emails are used as fallback sending emai...