Add Validations
Basic Validation Syntax
struct User
include CQL::ActiveRecord::Model(Int64)
db_context MyDB, :users
property id : Int64?
property name : String
property email : String
property age : Int32 = 0
validate :name, presence: true
validate :email, required: true, match: /@/
validate :age, gt: 0, lt: 120
def initialize(@name : String, @email : String, @age : Int32 = 0)
end
endAvailable Validators
Presence and Required
Size
Numeric Comparisons
Pattern Matching
Inclusion and Exclusion
Custom Error Messages
Checking Validity
Check if Valid
Access Errors
Validate and Raise
Custom Validators
Uniqueness Validation
Validations and Save
Verify It Works
Related
Last updated
Was this helpful?