14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/acts_as_paranoid/associations.rb', line 14
def belongs_to_with_deleted(target, scope = nil, options = {})
if scope.is_a?(Hash)
options = scope
scope = nil
end
with_deleted = options.delete(:with_deleted)
if with_deleted
if scope
old_scope = scope
scope = proc do |*args|
if old_scope.arity == 0
instance_exec(&old_scope).with_deleted
else
old_scope.call(*args).with_deleted
end
end
else
scope = proc do
if respond_to? :with_deleted
self.with_deleted
else
all
end
end
end
end
result = belongs_to_without_deleted(target, scope, **options)
result.values.last.options[:with_deleted] = with_deleted if with_deleted
result
end
|