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
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Deploy function not working - 503
Hellon i get this error message, when i try to deploy a new version of a function <html><body><h1>503 Service Unavailable</h1>No server is available to handle...