Back

[SOLVED] Populate fields in response

  • 0
  • Databases
  • Web
  • Cloud
omzi
5 Jun, 2023, 18:12

I have a Posts collection with the following schema.

TypeScript
title: String
content: String
isDraft: Boolean
authorId: String<Ref:User>

The authorId is a reference to a record on the Users collection. When fetching a document from the Posts collection, you can select the fields you want to be returned using Query.select([]). If you want to populate the authorId field with data from the Users collection, the only option you have currently is to make a second request which is not performant.

I suggest a new Query method be made to be able to populate fields. Maybe something like Query.populate(fieldToPopulate1, fieldToPopulate2, ...)? My current workaround is using database.getDocument when I need to populate ONE document and databases.listDocuments when I needed to populate multiple documents.

Is there a more performant way for achieving this?

TL;DR
The user is requesting a more performant way to populate fields in a response using Appwrite. Currently, they are making a second request to retrieve the related data, which is not efficient. They suggest a new Query method, `Query.populate()`, to accomplish this. The user is open to alternative solutions if available. The thread ends without a solution or further information.
Drake
5 Jun, 2023, 18:13

Are you on Appwrite Cloud?

omzi
5 Jun, 2023, 18:18

Yes I am

Drake
5 Jun, 2023, 18:22

Starting in version 1.3, Appwrite has built in relationship support to do what you mentioned. Cloud, however is on version 1.1.2 so it doesn't have relationship support. We're working on upgrading Cloud

omzi
5 Jun, 2023, 18:25

Okay. Thanks for the info.

Drake
5 Jun, 2023, 18:37

[SOLVED] Populate fields in response

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