Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Last active February 2, 2016 17:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcsmith/713c85cdbc820cca6d97 to your computer and use it in GitHub Desktop.
Save paulcsmith/713c85cdbc820cca6d97 to your computer and use it in GitHub Desktop.
Idea for check whether something changed from one value to another in a changeset
changeset |> changed?(:status, from: "pending", to: "canceled")
changeset |> changed?(:status, from: "attending") # for checking if it changed, but we don't care what it changed to
def changed?(changeset, field, from: from, to: to) do
Ecto.Changeset.get_field(changeset, field) == from
&& booking_changeset.changes[field] == to
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment