Updating the map in changeset

I have a schema that has one field data type of map. I want to update the map using changeset.
It’s look something like this

field(settings, :map) and map has coming data like this

settings: %{“one” => 5, “two” => 15}

so what I did

 def update_setting(%User{} = user, attrs) do
    |> User.update_setting_changeset(attrs)
    |> Repo.update()

My changeset function looks like this

def update_setting_changeset(user, attrs) do
    |> cast(attrs, [:settings])

how do I update the map here?

update_setting(user, %{settings: %{“one” => 10, “two” => 20}})

Thanks man.

1 Like