From 34bafa2463efb2641a65b50645b87ba43a7e35ed Mon Sep 17 00:00:00 2001 From: Subba Rao Pasupuleti Date: Thu, 8 Jul 2010 22:00:35 -0400 Subject: [PATCH] fixing duplicate records in target in memory --- .../associations/association_collection.rb | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 2855073..cd49a21 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -1,5 +1,4 @@ require 'set' - module ActiveRecord module Associations # AssociationCollection is an abstract class that provides common stuff to @@ -432,7 +431,14 @@ 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