From d2b9862b247693af16ad00e56d4510ef460bcea7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 20 Sep 2012 12:59:31 -0300 Subject: [PATCH] Freeze columns only once per Result Conflicts: activerecord/lib/active_record/result.rb --- activerecord/lib/active_record/result.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb index 9ceab2eabce94..b8d2cd28661c3 100644 --- a/activerecord/lib/active_record/result.rb +++ b/activerecord/lib/active_record/result.rb @@ -26,9 +26,15 @@ def to_hash private def hash_rows - @hash_rows ||= @rows.map { |row| - Hash[@columns.zip(row)] - } + @hash_rows ||= + begin + # We freeze the strings to prevent them getting duped when + # used as keys in ActiveRecord::Model's @attributes hash + columns = @columns.map { |c| c.dup.freeze } + @rows.map { |row| + Hash[columns.zip(row)] + } + end end end end