Helper function to get a changeset field

I’m struggling here on how to get a field value from a changeset.

First I had this very easy oneliner: changeset.changes[:email] || changeset.data[:email].

Then, I realized this was wrong and what I really wanted was something like:

case changeset do
  %Ecto.Changeset{changes: %{email: email}} -> email
  _ -> changeset.data[:email]
end

So, is there an ecto function that gets this correctly it for me?

Thanks

Haha, found it, sorry. :grimacing:

If you got curious, that’s it: Ecto.Changeset.get_field/3

3 Likes