Module: ActsAsParanoid::Associations::ClassMethods

Defined in:
lib/acts_as_paranoid/associations.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to_with_deleted(target, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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)\n          association = association(:\#{target})\n          return nil if association.options[:polymorphic] && association.klass.nil?\n          return \#{target}_without_unscoped(*args) unless association.klass.paranoid?\n          association.klass.with_deleted.scoping { \#{target}_without_unscoped(*args) }\n        end\n        alias_method_chain :\#{target}, :unscoped\n      RUBY\n    end\n  end\n\n  result\nend\n", __FILE__, __LINE__