module ActsAsParanoid::Associations::ClassMethods

Public Instance Methods

belongs_to_with_deleted(target, options = {}) click to toggle source
# File lib/acts_as_paranoid/associations.rb, line 11
      def belongs_to_with_deleted(target, options = {})
        with_deleted = options.delete(:with_deleted)
        result = belongs_to_without_deleted(target, options)

        if with_deleted
          result.options[:with_deleted] = with_deleted
          unless method_defined? "#{target}_with_unscoped"
            class_eval "              def #{target}_with_unscoped(*args)
                association = association(:#{target})
                return nil if association.options[:polymorphic] && association.klass.nil?
                return #{target}_without_unscoped(*args) unless association.klass.paranoid?
                association.klass.with_deleted.scoping { #{target}_without_unscoped(*args) }
              end
              alias_method_chain :#{target}, :unscoped
", __FILE__, __LINE__
          end
        end

        result
      end