Validate the association if :validate or :autosave is
turned on for the belongs_to association.
# File activerecord/lib/active_record/autosave_association.rb, line 343
def validate_belongs_to_association(reflection)
association = association_instance_get(reflection.name)
record = association && association.reader
return unless record && (record.changed_for_autosave? || custom_validation_context?)
begin
@validating_belongs_to_for ||= {}
@validating_belongs_to_for[association] = true
association_valid?(association, record)
ensure
@validating_belongs_to_for[association] = false
end
end