Module: Mongoid::Validations::ClassMethods
- Defined in:
- lib/mongoid/validations.rb
Instance Method Summary collapse
-
#validates_associated(*args) ⇒ Object
Validates whether or not an association is valid or not.
-
#validates_format_of(*args) ⇒ Object
Validates the format of a field.
-
#validates_length_of(*args) ⇒ Object
Validates the length of a field.
-
#validates_presence_of(*args) ⇒ Object
Validates whether or not a field is present - meaning nil or empty.
-
#validates_uniqueness_of(*args) ⇒ Object
Validates whether or not a field is unique against the documents in the database.
-
#validates_with(*args, &block) ⇒ Object
Add validation with the supplied validators forthe provided fields with options.
Instance Method Details
#validates_associated(*args) ⇒ Object
Validates whether or not an association is valid or not. Will correctly handle has one and has many associations.
108 109 110 |
# File 'lib/mongoid/validations.rb', line 108 def validates_associated(*args) validates_with(AssociatedValidator, _merge_attributes(args)) end |
#validates_format_of(*args) ⇒ Object
Validates the format of a field.
142 143 144 |
# File 'lib/mongoid/validations.rb', line 142 def validates_format_of(*args) validates_with(Mongoid::Validations::FormatValidator, _merge_attributes(args)) end |
#validates_length_of(*args) ⇒ Object
Validates the length of a field.
159 160 161 |
# File 'lib/mongoid/validations.rb', line 159 def validates_length_of(*args) validates_with(Mongoid::Validations::LengthValidator, _merge_attributes(args)) end |
#validates_presence_of(*args) ⇒ Object
Validates whether or not a field is present - meaning nil or empty.
176 177 178 |
# File 'lib/mongoid/validations.rb', line 176 def validates_presence_of(*args) validates_with(PresenceValidator, _merge_attributes(args)) end |
#validates_uniqueness_of(*args) ⇒ Object
Validates whether or not a field is unique against the documents in the database.
125 126 127 |
# File 'lib/mongoid/validations.rb', line 125 def validates_uniqueness_of(*args) validates_with(UniquenessValidator, _merge_attributes(args)) end |
#validates_with(*args, &block) ⇒ Object
See ActiveModel::Validations::With for full options. This is overridden to add autosave functionality when presence validation is added.
Add validation with the supplied validators forthe provided fields with options.
193 194 195 196 197 198 199 200 201 |
# File 'lib/mongoid/validations.rb', line 193 def validates_with(*args, &block) if args.first == PresenceValidator args.last[:attributes].each do |name| = relations[name.to_s] autosave(.merge!(autosave: true)) if end end super end |