diff options
author | eileencodes <eileencodes@gmail.com> | 2014-04-23 22:31:08 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2014-04-28 14:08:56 -0400 |
commit | 0d4bf17745eb0589431d8ec35eff1dc4eeacf899 (patch) | |
tree | ed7d4be266db678f52733a44a02de6196156d477 /activerecord/lib | |
parent | 3f5d14f78ea3549148757925898f776d68335090 (diff) | |
download | rails-0d4bf17745eb0589431d8ec35eff1dc4eeacf899.tar.gz rails-0d4bf17745eb0589431d8ec35eff1dc4eeacf899.tar.bz2 rails-0d4bf17745eb0589431d8ec35eff1dc4eeacf899.zip |
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.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 3a0a5165b6..cb64b7887e 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -194,7 +194,7 @@ module ActiveRecord options[:dependent] end - delete(:all, dependent: dependent).tap do + delete_all_with_dependency(dependent).tap do reset loaded! end @@ -259,6 +259,14 @@ module ActiveRecord 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. # |