aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2010-09-17 16:00:06 -0300
committerEmilio Tagua <miloops@gmail.com>2010-11-19 19:08:09 -0300
commitc0ad5e48f643e9721059e94ba23dab3159eebb93 (patch)
tree5f49da61727c62b53090455ea3f40212ce46c4a8 /activerecord/lib/active_record
parent448420ff7d082c98a538edd47dd24490e302c5ec (diff)
downloadrails-c0ad5e48f643e9721059e94ba23dab3159eebb93.tar.gz
rails-c0ad5e48f643e9721059e94ba23dab3159eebb93.tar.bz2
rails-c0ad5e48f643e9721059e94ba23dab3159eebb93.zip
Don't use identity map if loading readonly records, this will prevent changing readonly status on already loaded records.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation.rb11
1 files changed, 9 insertions, 2 deletions
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