aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-28 11:11:59 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-28 11:11:59 -0700
commit7707eb9e75587d655916645ad633cd6d45c40c03 (patch)
tree2e229508d25e1e634a0f6721906ef59a3daa3a6d /activerecord
parent3f5d14f78ea3549148757925898f776d68335090 (diff)
parente0e586094f968b1f8fa410aa84d105bc8e44e537 (diff)
downloadrails-7707eb9e75587d655916645ad633cd6d45c40c03.tar.gz
rails-7707eb9e75587d655916645ad633cd6d45c40c03.tar.bz2
rails-7707eb9e75587d655916645ad633cd6d45c40c03.zip
Merge pull request #14892 from eileencodes/breakup-complex-conditionals-on-delete
Breakup complex conditionals on delete
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 3a0a5165b6..9bf253d976 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
@@ -247,15 +247,15 @@ module ActiveRecord
_options = records.extract_options!
dependent = _options[:dependent] || options[:dependent]
- if records.first == :all
- if (loaded? || dependent == :destroy) && dependent != :delete_all
- delete_or_destroy(load_target, dependent)
- else
- delete_records(:all, dependent)
- end
+ records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
+ delete_or_destroy(records, dependent)
+ end
+
+ def delete_all_with_dependency(dependent)
+ if dependent == :delete_all
+ delete_records(:all, dependent)
else
- records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
- delete_or_destroy(records, dependent)
+ delete_or_destroy(load_target, dependent)
end
end