This paragraph mentions three functions that ensure data consistency:
Finally, the
validate/2
,unique_constraint/2
, andvalidate_number/2
functions validate the inbound data, ensuring consistency.
In the code shown earlier on the page, the first data consistency function is validate_required/2
, not validate/2
.
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