From 44e1be5cf2f63f7e7e2ce350cfc4af72c8cb9835 Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Sat, 17 Jan 2009 11:37:21 +0300 Subject: [PATCH] ActiveRecord::Base ordering: now checking if :order option is an empty string, so specifying :order => "" will not break queries any more. --- activerecord/lib/active_record/base.rb | 2 +- activerecord/test/cases/finder_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index cca012e..f4cc03a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1716,7 +1716,7 @@ module ActiveRecord #:nodoc: def add_order!(sql, order, scope = :auto) scope = scope(:find) if :auto == scope scoped_order = scope[:order] if scope - if order + if order.present? sql << " ORDER BY #{order}" sql << ", #{scoped_order}" if scoped_order else diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index d4d770b..a03f8b4 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -553,6 +553,10 @@ class FinderTest < ActiveRecord::TestCase assert_equal accounts(:signals37), Account.find_by_credit_limit(50, :order => 'id') assert_equal accounts(:rails_core_account), Account.find_by_credit_limit(50, :order => 'id DESC') end + + def test_find_by_one_attribute_with_empty_order_option + assert_equal accounts(:signals37), Account.find_by_credit_limit(50, :order => '') + end def test_find_by_one_attribute_with_conditions assert_equal accounts(:rails_core_account), Account.find_by_credit_limit(50, :conditions => ['firm_id = ?', 6]) -- 1.6.1