From edf6f3012dc94e5787ea717340176d7b72708e35 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 10 Sep 2013 14:29:37 +1000 Subject: [PATCH] backport fix for rails --- lib/freedom_patches/join_dependency.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/freedom_patches/join_dependency.rb diff --git a/lib/freedom_patches/join_dependency.rb b/lib/freedom_patches/join_dependency.rb new file mode 100644 index 00000000000..a88d575bb9c --- /dev/null +++ b/lib/freedom_patches/join_dependency.rb @@ -0,0 +1,22 @@ +# see PR: https://github.com/rails/rails/pull/12185 +# +class ActiveRecord::Associations::JoinDependency::JoinPart + + def extract_record(row) + # Used to be: Hash[column_names_with_alias.map{|cn, an| [cn, row[an]]}] + # that is fairly inefficient cause all the values are first copied + # in to an array only to construct the Hash + # This code is performance critical as it is called per row. + hash = {} + + index = 0 + while index < column_names_with_alias.length do + cn,an = column_names_with_alias[index] + hash[cn] = row[an] + index += 1 + end + + hash + end +end +