Saves the associated record if it’s new or :autosave is enabled on the association.
In addition, it will destroy the association if it was marked for destruction with mark_for_destruction.
# File activerecord/lib/active_record/autosave_association.rb, line 331 def save_belongs_to_association(reflection) if association = association_instance_get(reflection.name) if reflection.options[:autosave] && association.marked_for_destruction? association.destroy else association.save(false) if association.new_record? || reflection.options[:autosave] if association.updated? self[reflection.primary_key_name] = association.id # TODO: Removing this code doesn't seem to matterâ¦ if reflection.options[:polymorphic] self[reflection.options[:foreign_type]] = association.class.base_class.name.to_s end end end end end