1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove deprecated conditions parameter from #delete_all

This commit is contained in:
Rafael Mendonça França 2016-12-29 16:01:16 -05:00
parent d31a6d1384
commit e7381d289e
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
3 changed files with 13 additions and 27 deletions

View file

@ -1,4 +1,4 @@
* Remove deprecated conditions parameter from `#destroy_all`.
* Remove deprecated conditions parameter from `#destroy_all` and `#delete_all`.
*Rafael Mendonça França*

View file

@ -495,7 +495,7 @@ module ActiveRecord
#
# Post.limit(100).delete_all
# # => ActiveRecord::ActiveRecordError: delete_all doesn't support limit
def delete_all(conditions = nil)
def delete_all
invalid_methods = INVALID_METHODS_FOR_DELETE_ALL.select do |method|
value = get_value(method)
SINGLE_VALUE_METHODS.include?(method) ? value : value.any?
@ -504,27 +504,19 @@ module ActiveRecord
raise ActiveRecordError.new("delete_all doesn't support #{invalid_methods.join(', ')}")
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
stmt = Arel::DeleteManager.new
stmt.from(table)
if has_join_values?
@klass.connection.join_to_delete(stmt, arel, arel_attribute(primary_key))
else
stmt = Arel::DeleteManager.new
stmt.from(table)
if has_join_values?
@klass.connection.join_to_delete(stmt, arel, arel_attribute(primary_key))
else
stmt.wheres = arel.constraints
end
affected = @klass.connection.delete(stmt, "SQL", bound_attributes)
reset
affected
stmt.wheres = arel.constraints
end
affected = @klass.connection.delete(stmt, "SQL", bound_attributes)
reset
affected
end
# Deletes the row with a primary key matching the +id+ argument, using a

View file

@ -1011,12 +1011,6 @@ class RelationTest < ActiveRecord::TestCase
assert ! davids.loaded?
end
def test_delete_all_with_conditions_is_deprecated
assert_deprecated do
assert_difference("Author.count", -1) { Author.delete_all(name: "David") }
end
end
def test_delete_all_loaded
davids = Author.where(name: "David")