提交 1c851b8c 编写于 作者: E eileencodes

remove need for :all symbol

Refactor delete_count method to only handle delete_all or nullify/nil cases
and not destroy and switch to if/else rather than case statement. This
refactoring allows removal of :all symbol usage.
上级 d8ae2764
......@@ -105,11 +105,8 @@ def inverse_updates_counter_cache?(reflection = reflection())
}
end
def delete_count(records, method, scope)
case method
when :destroy
records.length
when :delete_all
def delete_count(method, scope)
if method == :delete_all
scope.delete_all
else
scope.update_all(reflection.foreign_key => nil)
......@@ -117,23 +114,19 @@ def delete_count(records, method, scope)
end
def delete_all_records(method)
scope = self.scope
count = delete_count(:all, method, scope)
count = delete_count(method, self.scope)
update_counter(-count)
end
# Deletes the records according to the <tt>:dependent</tt> option.
def delete_records(records, method)
scope = self.scope.where(reflection.klass.primary_key => records)
count = delete_count(records, method, scope)
if method == :destroy
count = records.length
records.each(&:destroy!)
update_counter(-count) unless inverse_updates_counter_cache?
else
scope = self.scope.where(reflection.klass.primary_key => records)
count = delete_count(method, scope)
update_counter(-count)
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册