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/has_many_association.rb, line 11
      def handle_dependency
        case options[:dependent]
        when :restrict_with_exception
          raise ActiveRecord::DeleteRestrictionError.new(reflection.name) unless empty?

        when :restrict_with_error
          unless empty?
            record = owner.class.human_attribute_name(reflection.name).downcase
            message = owner.errors.generate_message(:base, :'restrict_dependent_destroy.many', record: record, raise: true) rescue nil
            if message
              ActiveSupport::Deprecation.warn(                The error key `:'restrict_dependent_destroy.many'` has been deprecated and will be removed in Rails 5.1.                Please use `:'restrict_dependent_destroy.has_many'` instead..squish)
            end
            owner.errors.add(:base, message || :'restrict_dependent_destroy.has_many', record: record)
            throw(:abort)
          end

        else
          if options[:dependent] == :destroy
            # No point in executing the counter update since we're going to destroy the parent anyway
            load_target.each { |t| t.destroyed_by_association = reflection }
            destroy_all
          else
            delete_all
          end
        end
      end
Register or log in to add new notes.