mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix extracting references
via order_values
to respect quoting
This commit is contained in:
parent
98d12f1ef3
commit
5dafa72935
2 changed files with 7 additions and 1 deletions
|
@ -1122,7 +1122,7 @@ module ActiveRecord
|
||||||
validate_order_args(order_args)
|
validate_order_args(order_args)
|
||||||
|
|
||||||
references = order_args.grep(String)
|
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?
|
references!(references) if references.any?
|
||||||
|
|
||||||
# if a symbol is given we prepend the quoted table name
|
# if a symbol is given we prepend the quoted table name
|
||||||
|
|
|
@ -1717,6 +1717,9 @@ class RelationTest < ActiveRecord::TestCase
|
||||||
scope = Post.order("comments.body")
|
scope = Post.order("comments.body")
|
||||||
assert_equal ["comments"], scope.references_values
|
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")
|
scope = Post.order("comments.body", "yaks.body")
|
||||||
assert_equal ["comments", "yaks"], scope.references_values
|
assert_equal ["comments", "yaks"], scope.references_values
|
||||||
|
|
||||||
|
@ -1735,6 +1738,9 @@ class RelationTest < ActiveRecord::TestCase
|
||||||
scope = Post.reorder("comments.body")
|
scope = Post.reorder("comments.body")
|
||||||
assert_equal %w(comments), scope.references_values
|
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")
|
scope = Post.reorder("comments.body", "yaks.body")
|
||||||
assert_equal %w(comments yaks), scope.references_values
|
assert_equal %w(comments yaks), scope.references_values
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue