From b2b13f32fb198a0daff130bc50f78b5a8f6d6607 Mon Sep 17 00:00:00 2001 From: Subba Rao Pasupuleti Date: Thu, 8 Jul 2010 22:20:24 -0400 Subject: [PATCH] fixing in memory duplicate records --- .../associations/association_collection.rb | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 615b7d2..2acd4a6 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -479,7 +479,13 @@ module ActiveRecord callback(:before_add, record) yield(record) if block_given? @target ||= [] unless loaded? - @target << record unless @reflection.options[:uniq] && @target.include?(record) + unless @reflection.options[:uniq] && @target.include?(record) + if i = @target.index(record) + @target[i] = record + else + @target << record + end + end callback(:after_add, record) set_inverse_instance(record, @owner) record -- 1.7.0.4