aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-08-01 05:31:59 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-08-01 05:32:43 +0900
commit25760a492118886f5ecf570458217be8ea978678 (patch)
treeb816816a2bcc74330015fd0e334d98cb35c7c785 /activerecord
parent673cf4f13b08438bd1bd751420da778c38145df3 (diff)
downloadrails-25760a492118886f5ecf570458217be8ea978678.tar.gz
rails-25760a492118886f5ecf570458217be8ea978678.tar.bz2
rails-25760a492118886f5ecf570458217be8ea978678.zip
Revert "Merge pull request #24131 from brchristian/limit_and_primary_key"
This reverts commit d162188dd662a7d9f62ba8431474f50bc35e3e93, reversing changes made to 3576782888c307e3e192c44e332b957cd1174128. Reason: #24131 conflicts the #5153's default order contract, it means that existing apps would be broken by that change. We don't want to break existing apps without a deprecation cycle.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
-rw-r--r--activerecord/test/cases/finder_test.rb15
3 files changed, 1 insertions, 22 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 456f569718..d1ae41ab97 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,9 +1,3 @@
-* Don't impose primary key order if limit() has already been supplied.
-
- Fixes #23607
-
- *Brian Christian*
-
* Add environment & load_config dependency to `bin/rake db:seed` to enable
seed load in environments without Rails and custom DB configuration
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 93f3b67686..c5562c1ff0 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -550,7 +550,7 @@ module ActiveRecord
end
def ordered_relation
- if order_values.empty? && primary_key && limit_value.blank?
+ if order_values.empty? && primary_key
order(arel_attribute(primary_key).asc)
else
self
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 5d643eed24..e73c88dd5d 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -1278,21 +1278,6 @@ class FinderTest < ActiveRecord::TestCase
end
end
- def test_first_and_last_with_limit_for_order_without_primary_key
- # While Topic.first should impose an ordering by primary key,
- # Topic.limit(n).first should not
-
- Topic.first.touch # PostgreSQL changes the default order if no order clause is used
-
- assert_equal Topic.limit(1).to_a.first, Topic.limit(1).first
- assert_equal Topic.limit(2).to_a.first, Topic.limit(2).first
- assert_equal Topic.limit(2).to_a.first(2), Topic.limit(2).first(2)
-
- assert_equal Topic.limit(1).to_a.last, Topic.limit(1).last
- assert_equal Topic.limit(2).to_a.last, Topic.limit(2).last
- assert_equal Topic.limit(2).to_a.last(2), Topic.limit(2).last(2)
- end
-
def test_finder_with_offset_string
assert_nothing_raised { Topic.offset("3").to_a }
end