I have a custom parametrized type called OneOf
that allows parsing to one of other structs.
embedded_schema do
field :my_field, OneOf, types: [SchemaA, SchemaB]
end
I would like to use it inside an array.
embedded_schema do
field :list_of_fields, {:array, {:parametrized, {OneOf, types: [SchemaA, SchemaB]}
end
According to docs, embeds_many
has a four-argument version embeds_many(name, schema, opts, list)
, but if I understand correctly, the last parameter is a do-block Ecto.Schema — Ecto v3.12.5
It seems that I should be able to do that with array:
@type composite() :: {:array, t()} | ...
@type t() :: primitive() | custom()
@type custom() :: module() | {:parameterized, {module(), term()}}
That is why, I’ve used field :list_of_fields, {:array, {:parametrized, {OneOf, types: [SchemaA, SchemaB]}
but I am getting
** (ArgumentError) invalid or unknown composite {:parameterized, {OneOf, [types: [SchemaA, SchemaB], discriminator: :name, mapping: %{"a" => SchemaA, "b" => SchemaB}]}} for field :list_of_fields. Did you mean to use :array or :map as first element of the tuple instead?
Do arrays support parametrized Ecto types?