diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-12-12 12:31:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-12 12:31:35 -0500 |
commit | a681eaf22955734c142609961a6d71746cfa0583 (patch) | |
tree | d1593d8c5ecaa9c93ed734533a865782b214e95a | |
parent | ec68e5d42d20befd85cdf22dd5d516b1adda7012 (diff) | |
parent | 2d78c66cd918b2cfde0308c0e4327943c30894f8 (diff) | |
download | rails-a681eaf22955734c142609961a6d71746cfa0583.tar.gz rails-a681eaf22955734c142609961a6d71746cfa0583.tar.bz2 rails-a681eaf22955734c142609961a6d71746cfa0583.zip |
Merge pull request #31403 from Edouard-chin/fix-quoted-columnname
Quote colum_names when building select:
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 749223422f..808f796abe 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1041,7 +1041,7 @@ module ActiveRecord if select_values.any? arel.project(*arel_columns(select_values.uniq)) elsif @klass.ignored_columns.any? - arel.project(*arel_columns(@klass.column_names)) + arel.project(*arel_columns(@klass.column_names.map(&:to_sym))) else arel.project(table[Arel.star]) end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 9e1b858bda..875b98f0b8 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1495,4 +1495,12 @@ class BasicsTest < ActiveRecord::TestCase # regular column assert query.include?("name") end + + test "column names are quoted when using #from clause and model has ignored columns" do + refute_empty Developer.ignored_columns + query = Developer.from("`developers`").to_sql + quoted_id = Developer.connection.quote_table_name("id") + + assert_match(/SELECT #{quoted_id}.* FROM `developers`/, query) + end end |