Skip to content
Browse files

return early in case the left or right side lists are empty

  • Loading branch information...
1 parent 75e29e8 commit b8ed2d5ddff3db22430de983ba072f57b8aa3c00 @tenderlove tenderlove committed Jan 14, 2011
Showing with 4 additions and 5 deletions.
  1. +4 −5 activerecord/lib/active_record/associations/association_collection.rb
View
9 activerecord/lib/active_record/associations/association_collection.rb
@@ -359,11 +359,7 @@ def load_target
reset
end
- if @target.any?
- @target = merge_target_lists(targets, @target)
- else
- @target = targets
- end
+ @target = merge_target_lists(targets, @target)
end
end
@@ -441,6 +437,9 @@ def add_record_to_target_with_callbacks(record)
private
def merge_target_lists(loaded, existing)
+ return loaded if existing.empty?
+ return existing if loaded.empty?
+
loaded.map do |f|
i = existing.index(f)
if i

0 comments on commit b8ed2d5

Please sign in to comment.
Something went wrong with that request. Please try again.