From c0ad5e48f643e9721059e94ba23dab3159eebb93 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 17 Sep 2010 16:00:06 -0300 Subject: Don't use identity map if loading readonly records, this will prevent changing readonly status on already loaded records. --- activerecord/lib/active_record/relation.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 3b22be78cb..b91ecb109a 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -61,7 +61,15 @@ module ActiveRecord def to_a return @records if loaded? - @records = eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values) + readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value + + @records = if readonly + IdentityMap.without do + eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values) + end + else + eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values) + end preload = @preload_values preload += @includes_values unless eager_loading? @@ -69,7 +77,6 @@ module ActiveRecord # @readonly_value is true only if set explicitly. @implicit_readonly is true if there # are JOINS and no explicit SELECT. - readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value @records.each { |record| record.readonly! } if readonly @loaded = true -- cgit v1.2.3