Flowdock
replace(record, save = true) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/associations/has_one_association.rb, line 7
      def replace(record, save = true)
        raise_on_type_mismatch(record) if record
        load_target

        reflection.klass.transaction do
          if target && target != record
            remove_target!(options[:dependent]) unless target.destroyed?
          end

          if record
            set_owner_attributes(record)
            set_inverse_instance(record)

            if owner.persisted? && save && !record.save
              nullify_owner_attributes(record)
              set_owner_attributes(target) if target
              raise RecordNotSaved, "Failed to save the new associated #{reflection.name}."
            end
          end
        end

        self.target = record
      end
Register or log in to add new notes.