diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-26 17:25:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-26 17:25:45 -0400 |
commit | 61cc630ac7e7f8554dc049a3e5a2509c00303ef8 (patch) | |
tree | 96862a3875012ea78c792672cb0427eea7b1c148 /activerecord | |
parent | 7b841b61f57e0329be01e943b2ed157b0e11f4f8 (diff) | |
parent | 5dafa72935fbb0656f814f26f94e46f545890214 (diff) | |
download | rails-61cc630ac7e7f8554dc049a3e5a2509c00303ef8.tar.gz rails-61cc630ac7e7f8554dc049a3e5a2509c00303ef8.tar.bz2 rails-61cc630ac7e7f8554dc049a3e5a2509c00303ef8.zip |
Merge pull request #29571 from kamipo/fix_extracting_references_via_order_values
Fix extracting `references` via `order_values` to respect quoting
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 6ccdd7adcb..d44f6fd572 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1122,7 +1122,7 @@ module ActiveRecord validate_order_args(order_args) references = order_args.grep(String) - references.map! { |arg| arg =~ /^([a-zA-Z]\w*)\.(\w+)/ && $1 }.compact! + references.map! { |arg| arg =~ /^\W?(\w+)\W?\./ && $1 }.compact! references!(references) if references.any? # if a symbol is given we prepend the quoted table name diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 86f3b0b962..dc81f13fe9 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1717,6 +1717,9 @@ class RelationTest < ActiveRecord::TestCase scope = Post.order("comments.body") assert_equal ["comments"], scope.references_values + scope = Post.order("#{Comment.quoted_table_name}.#{Comment.quoted_primary_key}") + assert_equal ["comments"], scope.references_values + scope = Post.order("comments.body", "yaks.body") assert_equal ["comments", "yaks"], scope.references_values @@ -1735,6 +1738,9 @@ class RelationTest < ActiveRecord::TestCase scope = Post.reorder("comments.body") assert_equal %w(comments), scope.references_values + scope = Post.reorder("#{Comment.quoted_table_name}.#{Comment.quoted_primary_key}") + assert_equal ["comments"], scope.references_values + scope = Post.reorder("comments.body", "yaks.body") assert_equal %w(comments yaks), scope.references_values |