I can’t update the nested settings with ecto, I either get a set of changes “no change” or an error. Migration:
def change do
create table(:trees) do
...
add :settings, :map
The settings are as follows:
defmodule Final.TreeSettings do
use Ecto.Schema
embedded_schema do
...
field :columns, :map
timestamps
end
end
Pay attention to the map of nested columns.
I can easily insert a new line in the tree:
changeset = Tree.changeset(%Tree{}, %{user_id: user_id, name: x})
|> Ecto.Changeset.put_embed(:settings, treeSettings)
But updating it just doesn't work either:
get_tree = Repo.one! from p in Tree, where: p.name == ^tree["name"], where: p.user_id == ^user_id
settingss = get_tree.settings
settingss = Kernel.update_in(settingss.columns[tree["setting"]][tree["type"]], fn x -> "asdasd" end)
changeset =
get_tree
|> Ecto.Changeset.change
|> Ecto.Changeset.put_embed(:settings, settingss)
IO.inspect changeset
It gives:
#Ecto.Changeset<action: nil, changes: %{}, errors: [], data: #Final.Tree<>,
valid?: true>
source
share