Method: Immortal::ClassMethods#without_default_scope

Defined in:
lib/immortal.rb

#without_default_scopeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/immortal.rb', line 23

def without_default_scope
  new_scope = self.unscoped
  our_scope = self.current_scope || self.unscoped

  non_immortal_constraints_sql = our_scope.arel.constraints.to_a.map do |constraint|
    constraint.to_sql.split('AND').reject{|clause| clause.include?('deleted')}
  end.flatten.join(' AND ')

  new_scope = new_scope.merge(our_scope.except(:where))
  new_scope = new_scope.where(non_immortal_constraints_sql)

  unscoped.merge(new_scope).scoping do
    yield
  end
end