From 91fec0d24d50d3b3e90c48b2501ca913544781cc Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 1 Sep 2010 12:04:29 -0400 Subject: order should always be concatenated. order that is declared first has highest priority in all cases. Here are some examples. Car.order('name desc').find(:first, :order => 'id').name Car.named_scope_with_order.named_scope_with_another_order Car.order('id DESC').scoping do Car.find(:first, :order => 'id asc') end No special treatment to with_scope or scoping. Also note that if default_scope declares an order then the order declared in default_scope has the highest priority unless with_exclusive_scope is used. Signed-off-by: Santiago Pastorino --- activerecord/lib/active_record/relation/spawn_methods.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 4b2c647a26..e3f1496b9a 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -99,9 +99,8 @@ module ActiveRecord relation = relation.readonly(options[:readonly]) if options.key? :readonly - # Give precedence to newly-applied orders and groups to play nicely with with_scope [:group, :order].each do |finder| - relation.send("#{finder}_values=", Array.wrap(options[finder]) + relation.send("#{finder}_values")) if options.has_key?(finder) + relation.send("#{finder}_values=", relation.send("#{finder}_values") + Array.wrap(options[finder])) if options.has_key?(finder) end relation = relation.where(options[:conditions]) if options.has_key?(:conditions) -- cgit v1.2.3