I have a schema that has a dynamic JSON field (check_result
):
schema "checks" do
field(:check_name, :string)
field(:version, :integer)
field(:status, Ecto.Enum, values: [:success, :failure, :inactive, :warning])
field(:check_result, :map)
timestamps()
end
I have separated embedded schemas for different scenarios, an example would be:
embedded_schema do
field(:content_type_options, {:array, :string})
end
The job of these embedded schemas is casting of data and validation.
I would like to have the ability of casting/validating data when the data is fetched from the database, however I would like it to be loosely coupled, for example the approach that polymorphic embeds uses is not what I am looking for, as you have to place all the definitions in the parent schema:
schema "reminders" do
field :date, :utc_datetime
field :text, :string
polymorphic_embeds_one :channel,
types: [
sms: MyApp.Channel.SMS,
email: MyApp.Channel.Email
],
on_type_not_found: :raise,
on_replace: :update
end
Has anyone dealt with this before?