Permalink
Browse files

refactoring the postgres adapter index method to avoid inject and use…

… values_at. [#4976 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 47134a0 commit 6e655732226eef6fa04d8fc0c4ee1f0436688c49 @tenderlove tenderlove committed with josevalim Jun 25, 2010
Showing with 4 additions and 4 deletions.
  1. +4 −4 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -615,15 +615,15 @@ def indexes(table_name, name = nil)
indkey = row[2].split(" ")
oid = row[3]
- columns = query(<<-SQL, "Columns for index #{row[0]} on #{table_name}").inject({}) {|attlist, r| attlist[r[1]] = r[0]; attlist}
- SELECT a.attname, a.attnum
+ columns = Hash[query(<<-SQL, "Columns for index #{row[0]} on #{table_name}")]
+ SELECT a.attnum, a.attname
FROM pg_attribute a
WHERE a.attrelid = #{oid}
AND a.attnum IN (#{indkey.join(",")})
SQL
- column_names = indkey.map {|attnum| columns[attnum] }
- column_names.compact.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names)
+ column_names = columns.values_at(*indkey).compact
+ column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names)
end.compact
end

0 comments on commit 6e65573

Please sign in to comment.