Module: Mongoid::Validations::ClassMethods
- Defined in:
- lib/mongoid/validations.rb
Instance Method Summary collapse
-
#validates_relation(metadata) ⇒ Object
Adds an associated validator for the relation if the validate option was not provided or set to true.
-
#validates_with(*args, &block) ⇒ Object
Add validation with the supplied validators forthe provided fields with options.
-
#validating_with_query? ⇒ true, false
Are we currently performing a validation that has a query?.
Instance Method Details
#validates_relation(metadata) ⇒ Object
Adds an associated validator for the relation if the validate option was not provided or set to true.
124 125 126 127 128 |
# File 'lib/mongoid/validations.rb', line 124 def validates_relation() if .validate? validates_associated(.name) end end |
#validates_with(*args, &block) ⇒ Object
Note:
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.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/mongoid/validations.rb', line 143 def validates_with(*args, &block) if args.first == PresenceValidator args.last[:attributes].each do |name| = relations[name.to_s] if && [:autosave] != false autosave(.merge!(autosave: true)) end end end super end |
#validating_with_query? ⇒ true, false
Are we currently performing a validation that has a query?
163 164 165 |
# File 'lib/mongoid/validations.rb', line 163 def validating_with_query? Threaded.executing?("#{name}-validate-with-query") end |