aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb9
1 files changed, 3 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index f346a19a3a..4ce3b34819 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -478,13 +478,10 @@ module ActiveRecord
callback(:before_add, record)
yield(record) if block_given?
@target ||= [] unless loaded?
- index = @target.index(record)
- unless @reflection.options[:uniq] && index
- if index
- @target[index] = record
- else
+ if index = @target.index(record)
+ @target[index] = record
+ else
@target << record
- end
end
callback(:after_add, record)
set_inverse_instance(record, @owner)