From 91531372f9b7130f8a940cdb23f19984b65a60fa Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Wed, 26 Apr 2006 06:37:04 +0000 Subject: Add support for :order option to with_scope. Closes #3887. [eric.daspet@survol.net] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4274 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d7cbd010da..d4345807a5 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -837,7 +837,7 @@ module ActiveRecord #:nodoc: method_scoping.assert_valid_keys([ :find, :create ]) if f = method_scoping[:find] - f.assert_valid_keys([ :conditions, :joins, :select, :include, :from, :offset, :limit, :readonly ]) + f.assert_valid_keys([ :conditions, :joins, :select, :include, :from, :offset, :limit, :order, :readonly ]) f[:readonly] = true if !f[:joins].blank? && !f.has_key?(:readonly) end @@ -1012,8 +1012,8 @@ module ActiveRecord #:nodoc: add_conditions!(sql, options[:conditions], scope) sql << " GROUP BY #{options[:group]} " if options[:group] - sql << " ORDER BY #{options[:order]} " if options[:order] + add_order!(sql, options[:order]) add_limit!(sql, options, scope) sql @@ -1036,6 +1036,15 @@ module ActiveRecord #:nodoc: end end + def add_order!(sql, order) + if order + sql << " ORDER BY #{order}" + sql << ", #{scope(:find, :order)}" if scoped?(:find, :order) + else + sql << " ORDER BY #{scope(:find, :order)}" if scoped?(:find, :order) + end + end + # The optional scope argument is for the current :find scope. def add_limit!(sql, options, scope = :auto) scope = scope(:find) if :auto == scope -- cgit v1.2.3