Populate enumeration

Has anyone populated an enumeration field type from an external API or file?
How would you go about this? The reason is to avoid rebuilding the application whenever I need to add a new enum value.

1 Like

I would recommend avoiding the enumeration field for that then and instead create a collection-type to store the values you want and use a oneWay relation (far left on the relation matrix) instead.


We can not use one-way relations for all of these fields, that would create too many unnecessary collection types. Isn’t there any work around that?

@DMehaffy is correct in the best way of doing this.
Possible workaround not endorsed btw, would be to grab it from the external API, then query the database check what is in it, and if it’s not in there update the database on startup.
This will slow down the startup etc and it can get quite big etc which will give more issues but might as I said work.

And how do we make an operation run everytime on the start up?

You can use bootstrap.js as that is the startup entry point for strapi :slightly_smiling_face:
Or you can also use cron.js if you want to do it let’s say refetch data at X amount even though server is running.

Create your own global service to deal with it, and call the service in cron.js or bootstrap.js.