Skip to content

Instantly share code, notes, and snippets.

@talum
Created May 28, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talum/0b1e99433e26948e93c4cfe28fc165b2 to your computer and use it in GitHub Desktop.
Save talum/0b1e99433e26948e93c4cfe28fc165b2 to your computer and use it in GitHub Desktop.
Invoice changeset with constraint
defmodule Registrar.Billing.Invoice do
import Ecto.Changeset
def changeset(%Invoice{} = invoice, attrs \\ %{}) do
  invoice
  |> cast(attrs, [
   :amount_due,
   :due_date,
   :scheduled_send_date,
   :email
  ])
  |> validate_required([
   :amount_due,
   :due_date,
   :scheduled_send_date,
   :email
  ])
  |> validate_due_date_not_past()
  |> unique_constraint(:email)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment