From c0bfa0bfc17f4aa615cd9d1006509e0d84b5692d Mon Sep 17 00:00:00 2001 From: Subba Rao Pasupuleti Date: Sat, 10 Jul 2010 12:29:09 -0400 Subject: In nested_attributes when association is not loaded and association record is saved and then in memory record attributes should be saved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5053 state:resolved] Signed-off-by: José Valim --- .../lib/active_record/associations/association_collection.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 7abb738a74..7100be0245 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -477,7 +477,14 @@ module ActiveRecord callback(:before_add, record) yield(record) if block_given? @target ||= [] unless loaded? - @target << record unless @reflection.options[:uniq] && @target.include?(record) + index = @target.index(record) + unless @reflection.options[:uniq] && index + if index + @target[index] = record + else + @target << record + end + end callback(:after_add, record) set_inverse_instance(record, @owner) record -- cgit v1.2.3