The “Give It a Try” exercise “Add a Custom Validation” challenges the reader to:
First, add a custom validation to the Product schema’s changeset that validates that
:unit_price
is greater than 0.00.
This step is unnecessary because the unit price validation was included in the code on page 77.
def changeset(product, attrs) do
product
|> cast(attrs, [:name, :description, :unit_price, :sku])
|> validate_required([:name, :description, :unit_price, :sku])
|> unique_constraint(:sku)
|> validate_number(:unit_price, greater_than: 0.0)
end
The rest of page 77 shows what happens when a changeset includes an invalid unit price.