instance method
association_valid?
Ruby on Rails 5.2.8.1
Since v2.3.18 PrivateSignature
association_valid?(reflection, record, index = nil)
Returns whether or not the association is valid and applies any errors to the parent, self, if it wasn’t. Skips any :autosave enabled records if they’re marked_for_destruction? or destroyed.
Parameters
-
reflectionreq -
recordreq -
indexopt = nil
Source
# File activerecord/lib/active_record/autosave_association.rb, line 324
def association_valid?(reflection, record, index = nil)
return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)
context = validation_context if custom_validation_context?
unless valid = record.valid?(context)
if reflection.options[:autosave]
indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord::Base.index_nested_attribute_errors)
record.errors.each do |attribute, message|
attribute = normalize_reflection_attribute(indexed_attribute, reflection, index, attribute)
errors[attribute] << message
errors[attribute].uniq!
end
record.errors.details.each_key do |attribute|
reflection_attribute =
normalize_reflection_attribute(indexed_attribute, reflection, index, attribute).to_sym
record.errors.details[attribute].each do |error|
errors.details[reflection_attribute] << error
errors.details[reflection_attribute].uniq!
end
end
else
errors.add(reflection.name)
end
end
valid
end
Defined in activerecord/lib/active_record/autosave_association.rb line 324
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::AutosaveAssociation