Module: Mongoid::Validatable::ClassMethods
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Extended In:
| |
Defined in: | lib/mongoid/validatable.rb |
Instance Attribute Summary
-
#validating_with_query? ⇒ true | false
readonly
Are we currently performing a validation that has a query?
Instance Method Summary
-
#validates_relation(association)
Adds an associated validator for the association if the validate option was not provided or set to true.
-
#validates_with(*args, &block)
Add validation with the supplied validators for the provided fields with options.
Instance Attribute Details
#validating_with_query? ⇒ true
| false
(readonly)
Are we currently performing a validation that has a query?
# File 'lib/mongoid/validatable.rb', line 167
def validating_with_query? Threaded.executing?("#{name}-validate-with-query") end
Instance Method Details
#validates_relation(association)
Adds an associated validator for the association if the validate option was not provided or set to true.
# File 'lib/mongoid/validatable.rb', line 131
def validates_relation(association) if association.validate? validates_associated(association.name) end end
#validates_with(*args, &block)
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 for the provided fields with options.
# File 'lib/mongoid/validatable.rb', line 149
def validates_with(*args, &block) if args.first == PresenceValidator args.last[:attributes].each do |name| association = relations[name.to_s] if association && association.autosave? Association::Referenced::AutoSave.define_autosave!(association) end end end super end