Created
May 28, 2019 17:37
-
-
Save talum/0b1e99433e26948e93c4cfe28fc165b2 to your computer and use it in GitHub Desktop.
Invoice changeset with constraint
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
defmodule Registrar.Billing.Invoice do | |
import Ecto.Changeset | |
def changeset(%Invoice{} = invoice, attrs \\ %{}) do | |
invoice | |
|> cast(attrs, [ | |
:amount_due, | |
:due_date, | |
:scheduled_send_date, | |
]) | |
|> validate_required([ | |
:amount_due, | |
:due_date, | |
:scheduled_send_date, | |
]) | |
|> 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