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.
# File activerecord/lib/active_record/autosave_association.rb, line 278
def association_valid?(reflection, association)
return true if association.destroyed? || association.marked_for_destruction?
unless valid = association.valid?
if reflection.options[:autosave]
association.errors.each_error do |attribute, error|
attribute = "#{reflection.name}.#{attribute}"
errors.add(attribute, error.dup) unless errors.on(attribute)
end
else
errors.add(reflection.name)
end
end
valid
end