Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Whats a good way to check if a change set is new ?
defmodule MyApp.Mymodel do
schema "the_table" do
field :uuid, :string
...
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
...
|> put_uuid()
end
def put_uuid(chanageset) do
case changeset do
%Ecto.Changeset{valid?: true } ->
put_change(changeset, :uuid, Ecto.UUID.generate)
_ ->
changeset
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.