aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-07-16 22:34:51 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-07-18 03:27:55 +0900
commit972f0d6cb6c9d510b9b32e7f4138184154ab70eb (patch)
tree8d719cba74fbf68bd0aa0f2cc4338f0e1778bc4a /activerecord/lib/active_record/persistence.rb
parent8acca896cbaa01f6fc51969601888a440e83d53a (diff)
downloadrails-972f0d6cb6c9d510b9b32e7f4138184154ab70eb.tar.gz
rails-972f0d6cb6c9d510b9b32e7f4138184154ab70eb.tar.bz2
rails-972f0d6cb6c9d510b9b32e7f4138184154ab70eb.zip
`Persistence#delete` should not be affected by scoping
`self.class.delete` is delegated to `all` and `all` is affected by scoping. It should use `unscoped` to not be affected by that.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index a9509e562a..2e6901eb0e 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -175,7 +175,7 @@ module ActiveRecord
# callbacks or any <tt>:dependent</tt> association
# options, use <tt>#destroy</tt>.
def delete
- self.class.delete(id) if persisted?
+ _relation_for_itself.delete_all if persisted?
@destroyed = true
freeze
end
@@ -555,6 +555,10 @@ module ActiveRecord
end
def relation_for_destroy
+ _relation_for_itself
+ end
+
+ def _relation_for_itself
self.class.unscoped.where(self.class.primary_key => id)
end