method

delete

rails latest stable - Class: ActiveRecord::Associations::HasOneAssociation
delete(method = options[:dependent])
public

No documentation available.

# File activerecord/lib/active_record/associations/has_one_association.rb, line 26
      def delete(method = options[:dependent])
        if load_target
          case method
          when :delete
            target.delete
          when :destroy
            target.destroyed_by_association = reflection
            target.destroy
            throw(:abort) unless target.destroyed?
          when :destroy_async
            if target.class.query_constraints_list
              primary_key_column = target.class.query_constraints_list.map(&:to_sym)
              id = primary_key_column.map { |col| target.public_send(col) }
            else
              primary_key_column = target.class.primary_key.to_sym
              id = target.public_send(primary_key_column)
            end

            enqueue_destroy_association(
              owner_model_name: owner.class.to_s,
              owner_id: owner.id,
              association_class: reflection.klass.to_s,
              association_ids: [id],
              association_primary_key_column: primary_key_column,
              ensuring_owner_was_method: options.fetch(:ensuring_owner_was, nil)
            )
          when :nullify
            target.update_columns(nullified_owner_attributes) if target.persisted?
          end
        end
      end