module Mongoid::Validatable::ClassMethods
Public Instance Methods
validates_relation(association)
click to toggle source
Adds an associated validator for the association if the validate option was not provided or set to true.
@example Set up validation.
Person.validates_relation(association)
@param [ Mongoid::Association::Relatable
] association The association metadata.
# File lib/mongoid/validatable.rb, line 131 def validates_relation(association) if association.validate? validates_associated(association.name) end end
validates_with(*args, &block)
click to toggle source
Add validation with the supplied validators for the provided fields with options.
@example Validate with a specific validator.
validates_with MyValidator, on: :create
@param [ ActiveModel::Validator…, Hash ] *args The validator classes
and options hash.
@note See ActiveModel::Validations::With for full options. This is
overridden to add autosave functionality when presence validation is added.
Calls superclass method
# 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
validating_with_query?()
click to toggle source
Are we currently performing a validation that has a query?
@example Are we validating with a query?
Model.validating_with_query?
@return [ true | false ] If we are validating with a query.
# File lib/mongoid/validatable.rb, line 167 def validating_with_query? Threaded.executing?("#{name}-validate-with-query") end