diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index b8187b1c6a..8b5e600c96 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -354,12 +354,13 @@ module ActiveRecord def add_to_target(record) callback(:before_add, record) yield(record) if block_given? - @target ||= [] unless loaded? + if @reflection.options[:uniq] && index = @target.index(record) @target[index] = record else @target << record end + callback(:after_add, record) set_inverse_instance(record) record |