提交 0d4bf177 编写于 作者: E eileencodes

write a new method to be accessed from delete_all

The delete method is very coupled with delete all even
though only a portion of the conditionals apply. Decoupling
this will make the code easier to understand and manipulate.
上级 3f5d14f7
......@@ -194,7 +194,7 @@ def delete_all(dependent = nil)
options[:dependent]
end
delete(:all, dependent: dependent).tap do
delete_all_with_dependency(dependent).tap do
reset
loaded!
end
......@@ -259,6 +259,14 @@ def delete(*records)
end
end
def delete_all_with_dependency(dependent)
if (loaded? || dependent == :destroy) && dependent != :delete_all
delete_or_destroy(load_target, dependent)
else
delete_records(:all, dependent)
end
end
# Deletes the +records+ and removes them from this association calling
# +before_remove+ , +after_remove+ , +before_destroy+ and +after_destroy+ callbacks.
#
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册