aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-09-18 16:09:13 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-09-18 16:09:13 -0700
commit6256734e2d0bdd89f4b5d11da259d40afa0c95c7 (patch)
treeef9e6a9f4506a71a902e9cd92284f72754adc56c /activerecord
parent096a57b7f340884175f724b55c7bbeda6318b356 (diff)
downloadrails-6256734e2d0bdd89f4b5d11da259d40afa0c95c7.tar.gz
rails-6256734e2d0bdd89f4b5d11da259d40afa0c95c7.tar.bz2
rails-6256734e2d0bdd89f4b5d11da259d40afa0c95c7.zip
ActiveRecord::Base#<=> has been removed. Primary keys may not be in order,
or even be numbers, so sorting by id doesn't make sense. Please use `sort_by` and specify the attribute you wish to sort with. For example, change: Post.all.to_a.sort to: Post.all.to_a.sort_by(&:id)
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md10
-rw-r--r--activerecord/lib/active_record/core.rb9
-rw-r--r--activerecord/test/cases/base_test.rb7
3 files changed, 10 insertions, 16 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index a2e2fed75f..474b11f537 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,13 @@
+* ActiveRecord::Base#<=> has been removed. Primary keys may not be in order,
+ or even be numbers, so sorting by id doesn't make sense. Please use `sort_by`
+ and specify the attribute you wish to sort with. For example, change:
+
+ Post.all.to_a.sort
+
+ to:
+
+ Post.all.to_a.sort_by(&:id)
+
* Fix: joins association, with defined in the scope block constraints by using several
where constraints and at least of them is not `Arel::Nodes::Equality`,
generates invalid SQL expression.
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 07d997b719..0bc6933918 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -308,15 +308,6 @@ module ActiveRecord
@attributes.frozen?
end
- # Allows sort on objects
- def <=>(other_object)
- if other_object.is_a?(self.class)
- self.to_key <=> other_object.to_key
- else
- super
- end
- end
-
# Returns +true+ if the record is read only. Records loaded through joins with piggy-back
# attributes will be marked as read only since they cannot be saved.
def readonly?
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 20c3a2b6a4..87597db7b0 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -558,13 +558,6 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
end
- def test_comparison
- topic_1 = Topic.create!
- topic_2 = Topic.create!
-
- assert_equal [topic_2, topic_1].sort, [topic_1, topic_2]
- end
-
def test_create_without_prepared_statement
topic = Topic.connection.unprepared_statement do
Topic.create(:title => 'foo')