mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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>
This commit is contained in:
parent
47134a04bb
commit
6e65573222
1 changed files with 4 additions and 4 deletions
|
@ -615,15 +615,15 @@ module ActiveRecord
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue