Back

Error during update document with a Two-way relationship.

  • 0
  • Databases
  • Web
  • Cloud
Fede_
14 May, 2024, 19:41

Hi, i have some problems during updating of a document in a Two-way relationship table.

I'm on: -Appwrite Cloud -Web SDK 10.2.0

DB structure:

TypeScript
food : {
  name : string (required),
  ingredients : relations to "food_ingredients" (manyToMany)
}

food_ingredients : {Β 
  quantity : integer (required),
  ingredients : One-way relation to "ingredients" (manyToMany),
  food: relations to "food" (manyToMany)
}

It's simple,

step to replicate:

  1. create food doc:
TypeScript
food = this.db.createDocument(this.base_db, 'food', Appwrite.ID.unique(), {name : 'food_1'})
  1. create food_ingredients with food relation doc:
TypeScript
this.db.createDocument(this.base_db, 'food_ingredients', Appwrite.ID.unique(), food_ingredients = {quantity : 1, ingredients : [ingredient.?id], food : [food.$id]})

now, Now if I take the food document, I also receive the associated food_ingredients list

  1. but, when i try to edit food doc, i receive an exception:
TypeScript
this.db.updateDocument(this.base_db, 'food', food.$id, {name : 'food_1_updated'})

I've tried:

TypeScript
this.db.updateDocument(this.base_db, 'food', food.$id, {name : 'food_1_updated', ingredients : null})

this.db.updateDocument(this.base_db, 'food', food.$id, {name : 'food_1_updated'},
ingredients : [])

this.db.updateDocument(this.base_db, 'food', food.$id, {name : 'food_1_updated'},
ingredients : [food_ingredients.$id])

but i alway receive:

TypeScript
{
  "name":"AppwriteException",
  "code":400,
  "type":"document_invalid_structure",
  "response":{
    "message":"Invalid document structure: Unknown attribute: 'food_ingredients'",
    "code":400,
    "type":"document_invalid_structure",
    "version":"0.13.23"
   }
 }

thanks everyone in advance

P.S:

TypeScript
funtions.client = new Appwrite.Client().setEndpoint().setProject()

this.db =  new Appwrite.Databases(functions.client),
TL;DR
Developers encountered an error while updating a document with a two-way relationship. The issue could be related to migration or automatic field addition. Confirming the problem's onset is crucial. To potentially fix this in the future, developers can use the Appwrite CLI to generate an `appwrite.json` for sharing project, database, and collection details.
Steven
14 May, 2024, 20:06

Something may have happened to your relationships during hte upgrade. Would you please provide your:

  1. project id
  2. database ids
  3. collection ids
  4. attributes for each collection.

The easiest way to gather this would be to use the Appwrite CLI and init your collection to generate an appwrite.json that you can share

Fede_
14 May, 2024, 20:19

sure, here it is

Fede_
14 May, 2024, 20:22

I think I created the db before the migration, but I certainly modified it these days

Steven
14 May, 2024, 21:36

do you ahve much data?

Steven
14 May, 2024, 21:55

ok i think i fixed the food collection. how's your food_ingredients collection. are you able to update documents in there?

Fede_
15 May, 2024, 08:54

no it's a test table.

Fede_
15 May, 2024, 08:55

Yeah now it's work.

food_ingredients table works fine

Fede_
15 May, 2024, 08:55

Thanks for your help πŸ™‚

Fede_
15 May, 2024, 08:56

For possible future situations, is there a way to fix this by myself?

Steven
15 May, 2024, 08:57

When did the problem start?

Fede_
15 May, 2024, 08:59

I agreed with this yesterday, I added the field to the food_ingredients table and it automatically added it to food too. When I tried to edit a doc in food, the exception was raised

Fede_
15 May, 2024, 09:00

I don't know if the problem arose from the migration or from the automatic addition of the field in food

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more