mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Revert "ActiveRecord::Base#<=> has been removed. Primary keys may not be in order," -- will be replaced with a check to ensure that the keys used for comparison are integers, and only fail if they are not.
This reverts commit 6256734e2d
.
Conflicts:
activerecord/CHANGELOG.md
This commit is contained in:
parent
661637e5b6
commit
430b252d3d
3 changed files with 16 additions and 12 deletions
|
@ -262,18 +262,6 @@
|
|||
|
||||
*kennyj*
|
||||
|
||||
* 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)
|
||||
|
||||
*Aaron Patterson*
|
||||
|
||||
* 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.
|
||||
|
|
|
@ -310,6 +310,15 @@ 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?
|
||||
|
|
|
@ -554,6 +554,13 @@ 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')
|
||||
|
|
Loading…
Reference in a new issue