Hey guys,
To sum up, I’m trying to get a default behaviour when trying to insert things. In my case, I’m trying to set a field is_deleted
to false
even if the user sets it to true
.
I’m trying to accomplish it by using the Map.merge
function just as follows:
def changeset(%Campaign{} = campaign, attrs) do
new_campaign = Map.merge(attrs, %{is_deleted: false})
campaign
|> cast(new_campaign, [:name, :mailing, :is_deleted])
|> changeset_cast
end
I’m getting this error:
(Ecto.CastError) expected params to be a map with atoms or string keys, got a map with mixed keys: %{:is_deleted => false, "is_deleted" => true, "mailing" => nil, "name" => nil}
I could just remove :is_deleted
from the function, but I wanna use the same function to update as well.
Any idea how to deal with?
Thanks!