From 972f0d6cb6c9d510b9b32e7f4138184154ab70eb Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 16 Jul 2017 22:34:51 +0900 Subject: `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. --- activerecord/lib/active_record/persistence.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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 :dependent association # options, use #destroy. 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 -- cgit v1.2.3