1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

quoted_table_name doesn't respect table alias

So using `arel_attribute(primary_key).asc` in `batch_order` instead.
This commit is contained in:
Ryuta Kamizono 2017-09-14 07:51:28 +09:00
parent 7d5399379c
commit 6a4c02b850
2 changed files with 12 additions and 1 deletions

View file

@ -271,7 +271,7 @@ module ActiveRecord
end
def batch_order
"#{quoted_table_name}.#{quoted_primary_key} ASC"
arel_attribute(primary_key).asc
end
def act_on_ignored_order(error_on_ignore)

View file

@ -614,6 +614,17 @@ class EachTest < ActiveRecord::TestCase
assert_equal expected, actual
end
test ".find_each respects table alias" do
assert_queries(1) do
table_alias = Post.arel_table.alias("omg_posts")
table_metadata = ActiveRecord::TableMetadata.new(Post, table_alias)
predicate_builder = ActiveRecord::PredicateBuilder.new(table_metadata)
posts = ActiveRecord::Relation.create(Post, table_alias, predicate_builder)
posts.find_each {}
end
end
test ".find_each bypasses the query cache for its own queries" do
Post.cache do
assert_queries(2) do