diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-17 16:00:06 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-11-19 19:08:09 -0300 |
commit | c0ad5e48f643e9721059e94ba23dab3159eebb93 (patch) | |
tree | 5f49da61727c62b53090455ea3f40212ce46c4a8 /activerecord/lib | |
parent | 448420ff7d082c98a538edd47dd24490e302c5ec (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 11 |
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 |