module Sequel
  module Plugins
    module Cascading
      def self.apply(model, options = {})
        Array(options[:destroy]).each do |assoc|
          model.instance_eval "before_destroy { #{assoc}_dataset.destroy }"
        end
        Array(options[:nullify]).each do |assoc|
          model.instance_eval "before_destroy { remove_all_#{assoc} }"
        end
        Array(options[:restrict]).each do |assoc|
          model.instance_eval "before_destroy { raise Error::InvalidOperation, 'Delete would orphan associated #{assoc}' unless #{assoc}_dataset.empty? }"
        end
      end
    end
  end
end

module Sequel
  module Plugins
    module Cascading
      def self.apply(model, options = {})
        Array(options[:destroy]).each do |assoc|
          model.instance_eval "def before_destroy; super; #{assoc}_dataset.destroy; end"
        end
        Array(options[:nullify]).each do |assoc|
          model.instance_eval "def before_destroy; super; remove_all_#{assoc}; end"
        end
        Array(options[:restrict]).each do |assoc|
          model.instance_eval "def before_destroy; super; raise Error::InvalidOperation, 'Delete would orphan associated #{assoc}' unless #{assoc}_dataset.empty?; end"
        end
      end
    end
  end
end

Use a before_destroy method instead of the old hook system to avoid deprecation warnings
Use a before_destroy method instead of the old hook system to avoid deprecation warnings

Signed-off-by: S. Brent Faulkner <fe025f82eb26909ef35ab792eedfa01fd68bfb52@gto.net>