web
web copied to clipboard
Properly update cluster read model with and empty check selection
The's some issue when saving an empty checks selection.
This code does not correctly update
changeset =
%ClusterReadModel{id: id}
|> ClusterReadModel.changeset(%{
selected_checks: checks
})
Ecto.Multi.update(multi, :cluster, changeset)
The following code works but it might be subject to race conditions.
See https://github.com/trento-project/web/pull/420/commits/55c52e3517700847fd58b1e29e1740263a4ea648
changeset =
ClusterReadModel
|> Repo.get(id)
# TODO: couldn't make it work with Ecto.Multi
# With following line when we receive an empty list of selected checks, the readmodel does not get updated
# %ClusterReadModel{id: id}
|> ClusterReadModel.changeset(%{
selected_checks: checks
})
Ecto.Multi.update(multi, :cluster, changeset)