Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed May 23, 2018
1 parent 1434cc6 commit de604c2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def self.acts_as_paranoid(options={})
alias_method :destroy_without_paranoia, :destroy

include Paranoia
class_attribute :paranoia_column, :paranoia_sentinel_value
class_attribute :paranoia_column, :paranoia_sentinel_value, :paranoia_default_scope_enabled

self.paranoia_column = (options[:column] || :deleted_at).to_s
self.paranoia_sentinel_value = options.fetch(:sentinel_value) { Paranoia.default_sentinel_value }
Expand All @@ -248,6 +248,7 @@ def self.paranoia_scope
class << self; alias_method :without_deleted, :paranoia_scope end

unless options[:without_default_scope]
self.paranoia_default_scope_enabled = true
default_scope { paranoia_scope }
end

Expand Down Expand Up @@ -292,7 +293,7 @@ module Validations
module UniquenessParanoiaValidator
def build_relation(klass, *args)
relation = super
return relation unless klass.respond_to?(:paranoia_column)
return relation unless klass.respond_to?(:paranoia_default_scope_enabled) && klass.paranoia_default_scope_enabled
arel_paranoia_scope = klass.arel_table[klass.paranoia_column].eq(klass.paranoia_sentinel_value)
if ActiveRecord::VERSION::STRING >= "5.0"
relation.where(arel_paranoia_scope)
Expand Down

0 comments on commit de604c2

Please sign in to comment.