yav
yav copied to clipboard
vnumber required
Some of our databases uses int 0 (not active) and int 1 (is active) however using vnumber.required fails since it sees a value of 0 as missing.
Whats the solution here whilst making the field required?
I don't get it. You give the validator a Golang's struct and want it to check the original database value? Of course, it won't work.
If zero value is OK, then you should simply NOT check the field as required. You can replace it with vnumber.BetweenInt(0, 1).
If the field value can be missing in the DB and you still want to separate nulls and zeroes, then you should change int to *int and validate it using vpointer package. Here is the example.
Of course, your ORM (or whatever you use to map DB values to struct) has to support such a mapping.