From a3210d90be844b306bbbf3324c7ad1ad389a14b9 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 17 Sep 2010 16:46:56 -0300 Subject: [PATCH] implicit_readonly is not set until records are loaded, just check readonly_value and then set readonly status. --- activerecord/lib/active_record/relation.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index b91ecb109ab1..500506506a5a 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -61,9 +61,7 @@ def respond_to?(method, include_private = false) def to_a return @records if loaded? - readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value - - @records = if readonly + @records = if @readonly_value IdentityMap.without do eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values) end @@ -77,6 +75,7 @@ def to_a # @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