aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSamer Masry <smasry@dryblis.com>2011-07-27 10:17:25 -0700
committerSamer Masry <smasry@dryblis.com>2011-07-27 10:17:25 -0700
commit18d307ed94ee9a8cd2dca117597f9e6afd1b6faa (patch)
treed5bba453fc2629b24e92191bbbc9cb0e0bdcc0dc /activerecord
parentfa2bfd832c1d1e997d93c2269a485cc74782c86d (diff)
downloadrails-18d307ed94ee9a8cd2dca117597f9e6afd1b6faa.tar.gz
rails-18d307ed94ee9a8cd2dca117597f9e6afd1b6faa.tar.bz2
rails-18d307ed94ee9a8cd2dca117597f9e6afd1b6faa.zip
Reverse order fix when using function for ActiveRecord::QueryMethods Fixes #1697
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 1654ae1eac..3a7b245c51 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -312,7 +312,7 @@ module ActiveRecord
when String, Symbol
o.to_s.split(',').collect do |s|
s.strip!
- s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
+ (s if s =~ /\(/) || s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
end
else
o
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 821da91f0a..8a2cf0ef85 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -911,6 +911,11 @@ class RelationTest < ActiveRecord::TestCase
assert_equal 'zyke', FastCar.order_using_old_style.limit(1).first.name
end
+ def test_order_with_function_and_last
+ authors = Author.scoped
+ assert_equal authors(:bob), authors.order( "id asc, MAX( organization_id, owned_essay_id)" ).last
+ end
+
def test_order_using_scoping
car1 = CoolCar.order('id DESC').scoping do
CoolCar.find(:first, :order => 'id asc')