diff options
author | Kassio Borges <kassioborgesm@gmail.com> | 2013-12-13 11:37:19 -0200 |
---|---|---|
committer | Kassio Borges <kassioborgesm@gmail.com> | 2013-12-13 11:55:13 -0200 |
commit | b8569b9337309c2d6c72566a3426994b6da443d7 (patch) | |
tree | 17f7bbfffe28df27abd4faa14b7aa29d9a4ce50e /activerecord | |
parent | 7ce846c17784f8fca930c850ab6dae3555b66f8c (diff) | |
download | rails-b8569b9337309c2d6c72566a3426994b6da443d7.tar.gz rails-b8569b9337309c2d6c72566a3426994b6da443d7.tar.bz2 rails-b8569b9337309c2d6c72566a3426994b6da443d7.zip |
Fix mysql to support duplicated column names
This will fix the [broken
test](https://github.com/rails/rails/commit/4a2650836680f51490e999c3c8441a2f9adff96e)
`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.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 11 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index c4dcba0501..760f1435eb 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -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([], []) diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 7a00f7fa8f..5125d5df2a 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -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 |