diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-14 07:51:28 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-14 07:53:15 +0900 |
commit | 6a4c02b850396b9d9e6f3ec8828b613459b71223 (patch) | |
tree | 9e4bb55181e16241b4fc0766bdb45a4c366d2150 /activerecord | |
parent | 7d5399379cb9ac2d3ffafa28fdc844d7b6c18ab8 (diff) | |
download | rails-6a4c02b850396b9d9e6f3ec8828b613459b71223.tar.gz rails-6a4c02b850396b9d9e6f3ec8828b613459b71223.tar.bz2 rails-6a4c02b850396b9d9e6f3ec8828b613459b71223.zip |
`quoted_table_name` doesn't respect table alias
So using `arel_attribute(primary_key).asc` in `batch_order` instead.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/batches_test.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index 655508770f..356ad0dcd6 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -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) diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 53c1e61ad1..c965404b07 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -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 |