diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-07 11:13:15 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-07 11:13:15 +0900 |
commit | a194c527fa7b16840fd1b1250dc9f624c6536546 (patch) | |
tree | 3ac66e20f096f5d2df61bd1dc238b765f5a1f09e /activerecord | |
parent | 4f8d7024130411783d327cf978552135a2b62c30 (diff) | |
download | rails-a194c527fa7b16840fd1b1250dc9f624c6536546.tar.gz rails-a194c527fa7b16840fd1b1250dc9f624c6536546.tar.bz2 rails-a194c527fa7b16840fd1b1250dc9f624c6536546.zip |
Fix `pluck` with eager loading to respect `offset`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index ff06ecbee1..b61e65cfb3 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -402,7 +402,7 @@ module ActiveRecord if using_limitable_reflections?(join_dependency.reflections) relation else - if relation.limit_value + if has_limit_or_offset? limited_ids = limited_ids_for(relation) limited_ids.empty? ? relation.none! : relation.where!(primary_key => limited_ids) end diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 5eda39a0c7..e682da6fed 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -688,6 +688,11 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal [], Topic.includes(:replies).limit(1).where("0 = 1").pluck(:id) end + def test_pluck_with_includes_offset + assert_equal [5], Topic.includes(:replies).order(:id).offset(4).pluck(:id) + assert_equal [], Topic.includes(:replies).order(:id).offset(5).pluck(:id) + end + def test_pluck_not_auto_table_name_prefix_if_column_included Company.create!(name: "test", contracts: [Contract.new(developer_id: 7)]) ids = Company.includes(:contracts).pluck(:developer_id) |