diff options
author | Abhay Nikam <nikam.abhay1@gmail.com> | 2019-02-19 21:10:53 +0530 |
---|---|---|
committer | Abhay Nikam <nikam.abhay1@gmail.com> | 2019-02-20 09:19:19 +0530 |
commit | 11c34d8ef44b95b3989cb8376af09842293c892c (patch) | |
tree | cc169fd1045bc1862f415fded1bf59e6e7359d9c | |
parent | 64ef5e2f9e854a7f988227d629a699f11a998b17 (diff) | |
download | rails-11c34d8ef44b95b3989cb8376af09842293c892c.tar.gz rails-11c34d8ef44b95b3989cb8376af09842293c892c.tar.bz2 rails-11c34d8ef44b95b3989cb8376af09842293c892c.zip |
Replaced usage of where.delete/destroy_all with delete/destroy_by
-rw-r--r-- | activerecord/lib/active_record/callbacks.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 2 | ||||
-rw-r--r-- | guides/source/active_record_basics.md | 2 |
5 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 5407af85ea..6b927e9797 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -95,7 +95,7 @@ module ActiveRecord # # private # def delete_parents - # self.class.where(parent_id: id).delete_all + # self.class.delete_by(parent_id: id) # end # end # diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 4b2e9ed81c..c20274420f 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1323,7 +1323,7 @@ module ActiveRecord def record_version_state_after_migrating(version) if down? migrated.delete(version) - ActiveRecord::SchemaMigration.where(version: version.to_s).delete_all + ActiveRecord::SchemaMigration.delete_by(version: version.to_s) else migrated << version ActiveRecord::SchemaMigration.create!(version: version.to_s) diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 510a275b4e..7763496519 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -161,7 +161,7 @@ module ActiveRecord # # Delete multiple rows # Todo.delete([2,3,4]) def delete(id_or_array) - where(primary_key => id_or_array).delete_all + delete_by(primary_key => id_or_array) end def _insert_record(values) # :nodoc: diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 75890c327a..0c8880a20e 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -99,7 +99,7 @@ class Topic < ActiveRecord::Base end def destroy_children - self.class.where("parent_id = #{id}").delete_all + self.class.delete_by(parent_id: id) end def set_email_address diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md index 4cf4111bf0..271d94c597 100644 --- a/guides/source/active_record_basics.md +++ b/guides/source/active_record_basics.md @@ -314,7 +314,7 @@ method: ```ruby # find and delete all users named David -User.where(name: 'David').destroy_all +User.destroy_by(name: 'David') # delete all users User.destroy_all |