Hello *
We have an Ecto embedded schema that we use to validate a request payload to our API (our schema is not tied to a database, we are using it just for validation purposes).
We had an :action
field which wasn’t validated and it had 2 kind of different possible “types”, now we would like to validate it against 2 different schemas according to the action type.
Hello *
We have an Ecto embedded schema that we use to validate a request payload to our API (our schema is not tied to a database, we are using it just for validation purposes).
We had an :action field which wasn’t validated and it had 2 kind of different possible “types”, now we would like to validate it against 2 different schemas according to the action type.
MainSchema:
embedded_schema do
field :name, :string
embeds_one :action, either: [FooAction, BarAction]
end
FooAction and BarAction are 2 different Ecto embedded schemas with their own validation rules and different fields.
FooAction:
embedded_schema do
field :a, :string
field :b, :string
end
BarAction
embedded_schema do
field :c, :integer
end