Last active
February 2, 2016 17:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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