method

handle_dependency

Importance_0
handle_dependency() 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/belongs_to_association.rb, line 7
      def handle_dependency
        return unless load_target

        case options[:dependent]
        when :destroy
          raise ActiveRecord::Rollback unless target.destroy
        when :destroy_async
          if reflection.foreign_key.is_a?(Array)
            primary_key_column = reflection.active_record_primary_key.map(&:to_sym)
            id = reflection.foreign_key.map { |col| owner.public_send(col.to_sym) }
          else
            primary_key_column = reflection.active_record_primary_key.to_sym
            id = owner.public_send(reflection.foreign_key.to_sym)
          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)
          )
        else
          target.public_send(options[:dependent])
        end
      end
Register or log in to add new notes.