As @NobbZ said, changeset is the local variable but the code editor is confused, because in Elixir function’s parenthesis are optional.
If you don’t wanna confuse the editor, write the function as follows,
defp put_hashed_password(ch) do
case ch.valid? do
true ->
changes = ch.changes
put_change(ch, :password_hash, hashpwsalt(changes.password))
_ ->
ch
end
end
No, the changes key is present on only Ecto.Changeset struct.
In your terminal inside the project directory, run iex -S mix and then %Ecto.Changeset{},
you’ll get #Ecto.Changeset<action: nil, changes: %{}, errors: [], data: nil, valid?: false>
Reading your code again, you’re actually passing the customer which is an Ecto.Changeset struct conforming to the %Customer{} struct, while matched as %Customer{} = customer (argument in the changeset function).
It means this changeset will allow only the keys specified in the Mango.CRM.Customer{} struct (which you aliased as alias Mango.CRM.Customer) and some other default keys, like changes, errors, valid? etc.
In that case if you write the put_hashed_password as follows, it will be clearer and less confusing, both for you and the code editor.
defp put_hashed_password(customer) do
case customer.valid? do
true ->
changes = customer.changes
put_change(customer, :password_hash, hashpwsalt(changes.password))
_ ->
customer
end
en