Merge pull request #29571 from kamipo/fix_extracting_references_via_order_values

Fix extracting `references` via `order_values` to respect quoting
This commit is contained in:
Rafael França 2017-06-26 17:25:45 -04:00 committed by GitHub
commit 61cc630ac7
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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