I have two objects, a company object and a user object. I create a company first then I create a user for the company. The structure for the company is as follows
{
name: "",
......
users: [Object object] //Relationship with user object
}
The user object is:
"id": userObject.$id,
"role": role,
"department": department,
"title": title,
"about": about
}```
Now, I update the company with the following piece of code:
let payload = { "id": company.$id, "name": company.name, "location": company.location, "website": company.website, "users": [{ "id": userObject.$id, "role": role, "department": department, "title": title, "about": about }] }
const updatedCompany = await database.updateDocument(
process.env.REACT_APP_APPWRITE_DATABASE_ID,
process.env.REACT_APP_APPWRITE_COMPANIES_COLLECTION_ID,
company.$id,
payload
)```
Problem is when I run this code, I get the following error message: Message: Invalid document structure: Missing required attribute "role"
What could I be doing wrong?
can you share the screenshot of attributes of both collections?
@kamal.panara here is the company collections:
@kamal.panara here is the users object
Oh, and when I inspect the request from the networks tab, I can clearly see that I am sending the correct payload:
{
"id": "65bd2e3105b07cd4346b",
"name": "Shield",
"location": "Nairobi, Kenya",
"website": "https://shield.com",
"users": [
{
"id": "65bd2e4a23d633740a80",
"role": "admin",
"department": "Mobamba",
"title": "Mo",
"about": "Mo"
}
]
}
can you show users relationship with companies ? like click edit attribute and share the screenshot of the popup.
No worries, here you go @kamal.panara
can you try running your web app in new incognito tab ?
looks like browser cache issue
Thanks, but I am still getting the same error
since user can belong to only 1 company, can you also try passing companies attribute in user object:
{
"id": company.$id,
"name": company.name,
"location": company.location,
"website": company.website,
"users": [{
"id": userObject.$id,
"role": role,
"department": department,
"title": title,
"about": about,
"companies": company.$id,
}]
}
if that also doesn't works, then some else will help you from the community, because I also think you are doing everything right.
and also since you are using Appwrite self-hosted, can you also mention the appwrite instance version?
Thank you @kamal.panara I am on appwrite 1.4.12, let me try out your suggestion
Recommended threads
- It says domain already used but I have d...
I accidentally deleted the project in which I used my domain originally (orexia.app) from name.com. Now I am trying to add it to a different project and it says...
- Is this normal in the self host custom d...
when i try to add custom domain to the project did not see this in 1.8.0 ok when pressed the retry it says "DNS verification failed with resolver 8.8.8.8. Domai...
- No server error on selfhosted appwrite
Please help me, my clients is ask what happen on their data? How can i make it up again?