Skip to content

Commit

Permalink
write a new method to be accessed from delete_all
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eileencodes committed Apr 28, 2014
1 parent 3f5d14f commit 0d4bf17
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
#
Expand Down

0 comments on commit 0d4bf17

Please sign in to comment.