Fix extracting `references` via `order_values` to respect quoting

This commit is contained in:
Ryuta Kamizono 2017-06-26 02:23:35 +09:00
parent 98d12f1ef3
commit 5dafa72935
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