aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-06-28 11:46:25 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-06-28 11:46:25 -0700
commita5cb5a5af611481e7a69b160983fcac68f37088c (patch)
treef79d9c929d616f0b0d6bd1233cc44bf4c673fc41 /activerecord/lib/active_record/base.rb
parent26caf32949f40993409f71887b2490722749022a (diff)
parenteb22c51173f3ebe0f5a53f8bc57ebc74e4f0a824 (diff)
downloadrails-a5cb5a5af611481e7a69b160983fcac68f37088c.tar.gz
rails-a5cb5a5af611481e7a69b160983fcac68f37088c.tar.bz2
rails-a5cb5a5af611481e7a69b160983fcac68f37088c.zip
Merge pull request #1860 from dmathieu/comparison
Allow comparison on model objects - Closes #1858
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rw-r--r--activerecord/lib/active_record/base.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index ebea4252f9..fd52038647 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1811,6 +1811,15 @@ MSG
@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
+ nil
+ end
+ end
+
# Backport dup from 1.9 so that initialize_dup() gets called
unless Object.respond_to?(:initialize_dup)
def dup # :nodoc: