rails/rails — pull request #15099 by eileencodes (2014-05-13 22:54:56+00:00)
Title: Refactor delete_records method

`delete_records` had a lot of conditionals and was generally confusing code.

This pulls out anything that deals with just `delete_all` into it's own method `delete_or_nullify_all_records` for any association that has delete_all run on it.

This uses a new `delete_count` method that takes a method and a scope and is shared between `delete_records` and `delete_or_nullify_all_records`. This handles whether `delete_all` or `update_all` is run on the scope — count being the number `update_counter` is getting passed.

The `delete_or_nullify_all_records` method had to be created in hm:t association as well because of how the methods are chained/coupled. I plan to refactor hm:t `delete_records` eventually as well.

This has allowed for the removal of using :all symbol to check if we are deleting all records further optimizing the code. I was then able to remove the unoptimized `records = load_target if records == :all` in `delete_records`.

The results of delete/delete_all/destroy/destroy_all are the same, this change decouples and improves this part of the code.

cc/ @tenderlove