-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem updating changesets with relations. #17
Comments
The problem seems to be here: https://github.com/izelnakri/paper_trail/blob/master/lib/paper_trail.ex#L278-Lundefined That returns: item_changes: %{current_status: 19,
key_results: [#Ecto.Changeset<action: :update,
changes: %{values: %{"current_value" => 19, "desired_value" => 100}},
errors: [], data: #Performancex.KeyResult<>, valid?: true>]
} And fails when you try to do |
item_changes should represent a simple map of the changes automatically generated from your changeset functions. %PaperTrail.Version{item_changes: %{}} is essentially the %Changeset{changes: %{}}. I've never seen a case where you would have a changeset inside a changeset.changes, it should always be a simple map. Are you trying to update relationships in one go? Can you provide the your controller code and the changeset you are updating? Seems like an interesting edge-case I would really like to know how you've ended up with a changeset inside a changeset. Lastly, thanks for reporting! |
Thank you for answering I have the objective and the params
%{
current_status: 2,
key_results: [
id: 2,
values: %{
current_value: 15,
desired_value: 100
}
]
} Then, I'm just doing:
Objective module: def changeset_for_update(struct, params \\ {}) do
struct
|> cast(params, [:current_status, :assessment])
|> cast_assoc(:key_results)
|> validate_required([:current_status, :key_results])
end |
related discussion: #18. Im closing this issue now. |
I'm trying to use
PaperTrail.update
to update a record that has ahas_many
relation, but it is triggering the next error:It works fine with
Repo.update
so, do you have any idea that could be happening?The text was updated successfully, but these errors were encountered: