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
- is `account.get()` safe to be used in th...
I want to user's `id` for authentication. However, a while ago I was told in this server not to use `account.get()` and instead add user preferences for that us...
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- [Beginner] CLI --queries Syntax Error & ...
Hi everyone! I am a beginner with Appwrite and trying to use the CLI, but I'm stuck with a syntax error. Any guidance would be greatly appreciated! 🙏 **Enviro...