aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
diff options
context:
space:
mode:
authorWojciech Wnętrzak <w.wnetrzak@gmail.com>2015-09-05 10:50:05 +0200
committerWojciech Wnętrzak <w.wnetrzak@gmail.com>2015-09-06 16:14:16 +0200
commitc82c5f8ffd7291186235c5912151c9dc0d262c4a (patch)
treee881e9d357f4368158e03724cb241265c717f8ae /activerecord/lib/active_record/relation.rb
parenta8f4568f5396b68ae81eddc636604bb78bb6632a (diff)
downloadrails-c82c5f8ffd7291186235c5912151c9dc0d262c4a.tar.gz
rails-c82c5f8ffd7291186235c5912151c9dc0d262c4a.tar.bz2
rails-c82c5f8ffd7291186235c5912151c9dc0d262c4a.zip
Deprecate passing conditions to AR::Relation destroy_all and delete_all methods
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r--activerecord/lib/active_record/relation.rb23
1 files changed, 10 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index e47b7b1ed9..bf08cdbbf3 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -418,7 +418,7 @@ module ActiveRecord
end
end
- # Destroys the records matching +conditions+ by instantiating each
+ # Destroys the records by instantiating each
# record and calling its +destroy+ method. Each object's callbacks are
# executed (including <tt>:dependent</tt> association options). Returns the
# collection of objects that were destroyed; each will be frozen, to
@@ -431,20 +431,15 @@ module ActiveRecord
# rows quickly, without concern for their associations or callbacks, use
# +delete_all+ instead.
#
- # ==== Parameters
- #
- # * +conditions+ - A string, array, or hash that specifies which records
- # to destroy. If omitted, all records are destroyed. See the
- # Conditions section in the introduction to ActiveRecord::Base for
- # more information.
- #
# ==== Examples
#
- # Person.destroy_all("last_login < '2004-04-04'")
- # Person.destroy_all(status: "inactive")
# Person.where(age: 0..18).destroy_all
def destroy_all(conditions = nil)
if conditions
+ ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
+ Passing conditions to destroy_all is deprecated and will be removed in Rails 5.1.
+ To achieve the same use where(conditions).destroy_all
+ MESSAGE
where(conditions).destroy_all
else
to_a.each(&:destroy).tap { reset }
@@ -478,15 +473,13 @@ module ActiveRecord
end
end
- # Deletes the records matching +conditions+ without instantiating the records
+ # Deletes the records without instantiating the records
# first, and hence not calling the +destroy+ method nor invoking callbacks. This
# is a single SQL DELETE statement that goes straight to the database, much more
# efficient than +destroy_all+. Be careful with relations though, in particular
# <tt>:dependent</tt> rules defined on associations are not honored. Returns the
# number of rows affected.
#
- # Post.delete_all("person_id = 5 AND (category = 'Something' OR category = 'Else')")
- # Post.delete_all(["person_id = ? AND (category = ? OR category = ?)", 5, 'Something', 'Else'])
# Post.where(person_id: 5).where(category: ['Something', 'Else']).delete_all
#
# Both calls delete the affected posts all at once with a single DELETE statement.
@@ -512,6 +505,10 @@ module ActiveRecord
end
if conditions
+ ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
+ Passing conditions to delete_all is deprecated and will be removed in Rails 5.1.
+ To achieve the same use where(conditions).delete_all
+ MESSAGE
where(conditions).delete_all
else
stmt = Arel::DeleteManager.new