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 320
def association_valid?(reflection, record)
return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)
validation_context = self.validation_context unless [:create, :update].include?(self.validation_context)
unless valid = record.valid?(validation_context)
if reflection.options[:autosave]
record.errors.each do |attribute, message|
attribute = "#{reflection.name}.#{attribute}"
errors[attribute] << message
errors[attribute].uniq!
end
else
errors.add(reflection.name)
end
end
valid
end