提交 540262af 编写于 作者: E eileencodes

early return on delete and destroy methods

When delete or destroy is called on all records nothing
is deleted or destroyed. Intead of running through the code and still
not deleteing anything, we should early return
上级 dbbcc838
......@@ -244,6 +244,7 @@ def count(column_name = nil, count_options = {})
# are actually removed from the database, that depends precisely on
# +delete_records+. They are in any case removed from the collection.
def delete(*records)
return if records.empty?
_options = records.extract_options!
dependent = _options[:dependent] || options[:dependent]
......@@ -257,6 +258,7 @@ def delete(*records)
# Note that this method removes records from the database ignoring the
# +:dependent+ option.
def destroy(*records)
return if records.empty?
records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
delete_or_destroy(records, :destroy)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册