Skip to content

Commit

Permalink
Fix mysql to support duplicated column names
Browse files Browse the repository at this point in the history
This will fix the [broken
test](4a26508)
 `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.
  • Loading branch information
kassio committed Dec 13, 2013
1 parent 7ce846c commit b8569b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -419,14 +419,19 @@ def exec_without_stmt(sql, name = 'SQL') # :nodoc:


if result if result
types = {} types = {}
fields = []
result.fetch_fields.each { |field| result.fetch_fields.each { |field|
field_name = field.name
fields << field_name

if field.decimals > 0 if field.decimals > 0
types[field.name] = Fields::Decimal.new types[field_name] = Fields::Decimal.new
else else
types[field.name] = Fields.find_type field types[field_name] = Fields.find_type field
end end
} }
result_set = ActiveRecord::Result.new(types.keys, result.to_a, types)
result_set = ActiveRecord::Result.new(fields, result.to_a, types)
result.free result.free
else else
result_set = ActiveRecord::Result.new([], []) result_set = ActiveRecord::Result.new([], [])
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/finder_test.rb
Expand Up @@ -855,7 +855,7 @@ def test_find_with_nil_inside_set_passed_for_attribute


def test_with_limiting_with_custom_select def test_with_limiting_with_custom_select
posts = Post.references(:authors).merge( 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' :limit => 3, :order => 'posts.id'
).to_a ).to_a
assert_equal 3, posts.size assert_equal 3, posts.size
Expand Down

0 comments on commit b8569b9

Please sign in to comment.