Back

Query one collection and fetch data from related collection

  • 1
  • Databases
  • Web
  • Cloud
kaushal91
11 Jun, 2024, 13:53

Hi everyone i have a database on appwrite named inventories which have relation with warehouses db like following:

  1. Two-way relationship
  2. Realted Collections -> warehouses
  3. Attribute Key -> warehouse (i name it warehouse)
  4. Attribute Key -> inventories
  5. Relation -> Many to Many (not sure if this could be a problem but open to suggestions)
  6. On deleting a document -> Cascade - delete all related documents

So how my setup is for example if i have "Hoodie" as inventory item i am going to create a row entry for Warehouse 1 and if it is going to Warehouse 2 then i will make another row entry in inventories collection. Open to suggestions on how to achieve an api call like this: const inventories = await databases.listDocuments( PRIVATE_APP_WRITE_DATABASE_ID, PRIVATE_APP_WRITE_INVENTORIES_COLLECTION_ID, [Query.contains('warehouse', [warehouseId])] ); bcoz when i do this it doesnt work and i want to fetch warehouse details in it.

Tech Stack: I am using Sveltekit 2.0 and warehouseId is passed as param as string.

TL;DR
Developers are having trouble querying a collection in Appwrite and fetching data from a related collection. The setup involves a two-way relationship between inventories and warehouses. Suggestions for achieving the desired API call are needed. The tech stack includes Sveltekit 2.0, and the warehouseId is passed as a string parameter.
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