Class: Mongoid::Validatable::AssociatedValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Mongoid::Validatable::AssociatedValidator
- Defined in:
- lib/mongoid/validatable/associated.rb
Overview
Validates whether or not an association is valid or not. Will correctly handle has one and has many associations.
Instance Method Summary collapse
-
#attributes ⇒ Object
Required by ‘validates_with` so that the validator gets added to the correct attributes.
-
#validate(document) ⇒ Object
Checks that the named associations of the given record (‘attributes`) are valid.
Instance Method Details
#attributes ⇒ Object
Required by ‘validates_with` so that the validator gets added to the correct attributes.
22 23 24 |
# File 'lib/mongoid/validatable/associated.rb', line 22 def attributes [:attributes] end |
#validate(document) ⇒ Object
Checks that the named associations of the given record (‘attributes`) are valid. This does NOT load the associations from the database, and will only validate records that are dirty or unpersisted.
If anything is not valid, appropriate errors will be added to the ‘document` parameter.
36 37 38 39 40 |
# File 'lib/mongoid/validatable/associated.rb', line 36 def validate(document) [:attributes].each do |attr_name| validate_association(document, attr_name) end end |