Remove deprecated conditions parameter from #delete_all

上级 d31a6d13
* Remove deprecated conditions parameter from `#destroy_all`.
* Remove deprecated conditions parameter from `#destroy_all` and `#delete_all`.
*Rafael Mendonça França*
......
......@@ -495,7 +495,7 @@ def destroy(id)
#
# 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 @@ def delete_all(conditions = nil)
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
else
stmt = Arel::DeleteManager.new
stmt.from(table)
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
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)
affected = @klass.connection.delete(stmt, "SQL", bound_attributes)
reset
affected
end
reset
affected
end
# Deletes the row with a primary key matching the +id+ argument, using a
......
......@@ -1011,12 +1011,6 @@ def test_delete_all
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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册