Airtable - Best practices for displaying a list of options (from the db)

I have a single select list in Airtable “typeBilan”.

image

How do I get the options directly from the database?
This case is simple, but I have other cases where there are more choices, and where more choices are likely to be added in the Airtable base. I want to sync those choices with WeWeb automatically.

@Joyce has shown a trick to do that in Build the WeWeb Public Roadmap - YouTube, but I feel like that trick falls short in a specific race condition: when no record contain a given option, this option will not show up in WeWeb.

The reason is that Joyce’s trick is to take a whole collection and do a “rollup” with true which only keeps different values, essentially making it an array of different values.
But if there are no value in the collection (AKA no record with such option) then the options that aren’t listed will not yield a choice either.

How can we work around that limitation? Since the new Airtable API, I suspect it should be possible to access a field’s metadata, such as the options. But this integration isn’t available yet in WeWeb. (and I’m not sure it’s achievable manually, even using the raw REST API)

Also, in the event of using Joyce’s trick, isn’t it better to avoid duplicating the same collection and rather achieve the same using a Formula? I am concerned with performances and Airtable API rate limits.
I suspect duplicating the same collection will yield more HTTP requests, but it depends on how WeWeb is optimized. Does it blindly re-run the same network requests for each collection? Or does it have some optimization to avoid doing unnecessary calls?


P.S: For the sake of documentation, here is the Airtable API endpoint I think we could call, to get all the options of a given field: Airtable Web API

Using Joyce’s trick, and using a Formula (instead of a new collection, by relying on an existing collection), here is how it can be achieved:

I’ve encountered the same issue, but if I understand correctly, Joyce’s trick only works if existing records contain the options (and might lead to performance issues). Airtable’s API has an endpoint for accessing base metadata, so for now I’m going to try to use that, but since I need to provide a personal access token I’m going to route this request through another API such as Xano to avoid exposing it in a WeWeb variable.

Unless I am mistaken and haven’t found how to access metadata through WeWeb’s Airtable plugin, an updated or entirely different plugin might be useful!

1 Like

Your solution is probably the only safe way to do it, until WeWeb adds a built-in way to fetch from the Airtable Metadata API.

1 Like

Hi @AmbroiseDhenain :wave:

My first thought here: why not have a dedicated table for the typeBilan options and use a reference field in other tables?

That way you keep things very flexible as your app evolves and you could have 2 collections in WeWeb without repeating data. (I think in the video you referenced, I hadn’t cleaned up the db so you had the same information twice but you don’t have to / shouldn’t)

What’s your full use case?

That’s just not how the database was built.
Using relationships is a workaround, but not necessarily a best practice.

1 Like