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
# 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
    class_eval "def \#{target}_with_unscoped(*args)\nassociation = association(:\#{target})\nreturn nil if association.options[:polymorphic] && association.klass.nil?\nreturn \#{target}_without_unscoped(*args) unless association.klass.paranoid?\nassociation.klass.with_deleted.scoping { \#{target}_without_unscoped(*args) }\nend\nalias_method_chain :\#{target}, :unscoped\n", __FILE__, __LINE__
  end

  result
end