aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_association.rb
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-05-17 09:11:25 -0400
committereileencodes <eileencodes@gmail.com>2014-05-18 07:52:04 -0400
commit540262afd7f1ebc675756fdeaee1a86c9f840f3e (patch)
tree9167138e50c34c6e7592384b3540963ef711f57e /activerecord/lib/active_record/associations/collection_association.rb
parentdbbcc8388acbcded4ef3a8b17213e3f16a354f32 (diff)
downloadrails-540262afd7f1ebc675756fdeaee1a86c9f840f3e.tar.gz
rails-540262afd7f1ebc675756fdeaee1a86c9f840f3e.tar.bz2
rails-540262afd7f1ebc675756fdeaee1a86c9f840f3e.zip
early return on delete and destroy methods
When delete or destroy is called on all records nothing is deleted or destroyed. Intead of running through the code and still not deleteing anything, we should early return
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index caf4e612f9..c5f7bcae7d 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -244,6 +244,7 @@ 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?
_options = records.extract_options!
dependent = _options[:dependent] || options[:dependent]
@@ -257,6 +258,7 @@ 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?(Fixnum) || record.kind_of?(String) }
delete_or_destroy(records, :destroy)
end