aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-10-06 03:37:27 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-10-06 03:39:48 +0900
commit9cbebd70eae7aa78a5b165dd3cae8e53c9a8ab83 (patch)
tree9949a953674b337572a0ca6e123970fa30ec98da /activerecord
parentb4dfc18d67ed9302fed8d680dfcb433b67a011eb (diff)
downloadrails-9cbebd70eae7aa78a5b165dd3cae8e53c9a8ab83.tar.gz
rails-9cbebd70eae7aa78a5b165dd3cae8e53c9a8ab83.tar.bz2
rails-9cbebd70eae7aa78a5b165dd3cae8e53c9a8ab83.zip
Move duplicated code to `delete_or_destroy` in `CollectionAssociation`
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index ceedf150e3..ed215fb22c 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -181,8 +181,6 @@ module ActiveRecord
# are actually removed from the database, that depends precisely on
# +delete_records+. They are in any case removed from the collection.
def delete(*records)
- return if records.empty?
- records = find(records) if records.any? { |record| record.kind_of?(Integer) || record.kind_of?(String) }
delete_or_destroy(records, options[:dependent])
end
@@ -192,8 +190,6 @@ module ActiveRecord
# Note that this method removes records from the database ignoring the
# +:dependent+ option.
def destroy(*records)
- return if records.empty?
- records = find(records) if records.any? { |record| record.kind_of?(Integer) || record.kind_of?(String) }
delete_or_destroy(records, :destroy)
end
@@ -376,6 +372,8 @@ module ActiveRecord
end
def delete_or_destroy(records, method)
+ return if records.empty?
+ records = find(records) if records.any? { |record| record.kind_of?(Integer) || record.kind_of?(String) }
records = records.flatten
records.each { |record| raise_on_type_mismatch!(record) }
existing_records = records.reject(&:new_record?)