Is it possible to use dynamically values for Ecto.Enum?

In our app, we define a DictionaryRegistry that creates an Registry and then starts two “TermDictionaries” that is a module that implements Agent behavior and defines some translations from external to internal terms.

The problem arrives when we need to define an embedded schema that has a field with the type Ecto.Enum and its values are those described in one of “TermDictionaries”.

However, neither Registry nor TermDictionary are started on compile time, so ecto macros can’t access it…

Any suggestion?

Hello, you could use custom validation

https://hexdocs.pm/ecto/Ecto.Changeset.html#validate_change/3

1 Like