Method: Iry::Macros#exclusion_constraint
- Defined in:
- lib/iry/macros.rb
#exclusion_constraint(key, name: nil, message: :taken) ⇒ void
This method returns an undefined value.
Tracks exclusion constraint for the given key and convert constraint errors into validation errors
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/iry/macros.rb', line 39 def exclusion_constraint( key, name: nil, message: :taken ) name ||= Constraint::Exclusion.infer_name(key, table_name) if constraints.key?(name) raise ArgumentError, "Constraint already exists" end self.constraints = constraints.dup constraints[name] = Constraint::Exclusion.new( key, message: , name: name ) end |