Module: Associates::Validations
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/associates/validations.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#valid_with_associates?(context = nil) ⇒ Boolean
Runs the model validations plus the associated models validations and merges each messages in the errors hash.
Instance Method Details
#valid_with_associates?(context = nil) ⇒ Boolean
Runs the model validations plus the associated models validations and merges each messages in the errors hash
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/associates/validations.rb', line 16 def valid_with_associates?(context = nil) # Model validations valid_without_associates?(context) # Associated models validations self.class.associates.each do |associate| model = send(associate.name) model.valid?(context) model.errors.each_entry do |attribute, | # Do not include association presence validation errors if associate.dependent_names.include?(attribute.to_s) next elsif respond_to?(attribute) errors.add(attribute, ) else errors.add(:base, model.errors.(attribute)) end end end errors..values.each(&:uniq!) errors.none? end |