Module: Mongoid::Validatable::ClassMethods
- Defined in:
- lib/mongoid/validatable.rb
Instance Method Summary collapse
-
#validates_relation(association) ⇒ Object
Adds an associated validator for the association if the validate option was not provided or set to true.
-
#validates_with(*args, &block) ⇒ Object
Add validation with the supplied validators for the provided fields with options.
-
#validating_with_query? ⇒ true | false
Are we currently performing a validation that has a query?.
Instance Method Details
#validates_relation(association) ⇒ Object
Adds an associated validator for the association if the validate option was not provided or set to true.
130 131 132 133 134 |
# File 'lib/mongoid/validatable.rb', line 130 def validates_relation(association) if association.validate? validates_associated(association.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 for the provided fields with options.
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/mongoid/validatable.rb', line 148 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 |
#validating_with_query? ⇒ true | false
Are we currently performing a validation that has a query?
166 167 168 |
# File 'lib/mongoid/validatable.rb', line 166 def validating_with_query? Threaded.executing?("#{name}-validate-with-query") end |