I have this schemaless changeset fields
data = %{}
types = %{name: :string, email: :string, age: :integer}
params = %{name: "Callum", email: "callum@example.com", age: 27}
changeset =
{data, types}
|> Ecto.Changeset.cast(params, Map.keys(types))
|> Ecto.Changeset.validate_required(...)
but also want to add dynamic embedded relations
embeds_many :response_1, Jsonb, on_replace: :delete do
field :order, :integer
field :text, :string
end
embeds_many :response_2, Jsonb, on_replace: :delete do
field :order, :integer
field :text, :string
end
embeds_many :response_3, Jsonb, on_replace: :delete do
field :order, :integer
field :text, :string
end
As you noticed the embed :response_x is dynamic (it grow or shrink) and I don’t want to hardcode these embedded relations. I need find a way to just enum the responses and build these relationships at the same time be able to cast them using cast_embed.
Any idea is greatly appreciated!