diff options
author | eileencodes <eileencodes@gmail.com> | 2014-05-17 09:11:25 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2014-05-18 07:52:04 -0400 |
commit | 540262afd7f1ebc675756fdeaee1a86c9f840f3e (patch) | |
tree | 9167138e50c34c6e7592384b3540963ef711f57e | |
parent | dbbcc8388acbcded4ef3a8b17213e3f16a354f32 (diff) | |
download | rails-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
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 2 |
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 |