1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix mysql to support duplicated column names

This will fix the [broken
test](4a26508366)
 `test_with_limiting_with_custom_select`.

The query's result was built in a hash with column name as key, if the
result have a duplicated column name the last value was
overriding the first one.
This commit is contained in:
Kassio Borges 2013-12-13 11:37:19 -02:00
parent 7ce846c177
commit b8569b9337
2 changed files with 9 additions and 4 deletions

View file

@ -419,14 +419,19 @@ module ActiveRecord
if result
types = {}
fields = []
result.fetch_fields.each { |field|
field_name = field.name
fields << field_name
if field.decimals > 0
types[field.name] = Fields::Decimal.new
types[field_name] = Fields::Decimal.new
else
types[field.name] = Fields.find_type field
types[field_name] = Fields.find_type field
end
}
result_set = ActiveRecord::Result.new(types.keys, result.to_a, types)
result_set = ActiveRecord::Result.new(fields, result.to_a, types)
result.free
else
result_set = ActiveRecord::Result.new([], [])

View file

@ -855,7 +855,7 @@ class FinderTest < ActiveRecord::TestCase
def test_with_limiting_with_custom_select
posts = Post.references(:authors).merge(
:includes => :author, :select => ' posts.*, authors.id as "author_id"',
:includes => :author, :select => 'posts.*, authors.id as "author_id"',
:limit => 3, :order => 'posts.id'
).to_a
assert_equal 3, posts.size