diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-09-04 23:59:40 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2010-09-05 08:28:11 -0300 |
commit | 708ee9c5ac6ef3ded22a716914a2c46136b5dfe0 (patch) | |
tree | aa7fd1e632eb04752aeae699e48011afe78740e6 /activerecord | |
parent | 16e078d908b79c78016e3a08afdd18a3dc77d40b (diff) | |
download | rails-708ee9c5ac6ef3ded22a716914a2c46136b5dfe0.tar.gz rails-708ee9c5ac6ef3ded22a716914a2c46136b5dfe0.tar.bz2 rails-708ee9c5ac6ef3ded22a716914a2c46136b5dfe0.zip |
Make scoped reorder override previous applied orders
[5528 state:committed]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 11 |
2 files changed, 15 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 78fa85e737..6005105cc9 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -6,7 +6,7 @@ module ActiveRecord extend ActiveSupport::Concern attr_accessor :includes_values, :eager_load_values, :preload_values, - :select_values, :group_values, :order_values, :joins_values, :where_values, :having_values, + :select_values, :group_values, :order_values, :reorder_flag, :joins_values, :where_values, :having_values, :limit_value, :offset_value, :lock_value, :readonly_value, :create_with_value, :from_value def includes(*args) @@ -53,7 +53,10 @@ module ActiveRecord def reorder(*args) relation = clone - relation.order_values = args if args.present? + if args.present? + relation.order_values = args + relation.reorder_flag = true + end relation end diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index e3f1496b9a..a6cf59fbf1 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -18,11 +18,20 @@ module ActiveRecord end end - (Relation::MULTI_VALUE_METHODS - [:joins, :where]).each do |method| + (Relation::MULTI_VALUE_METHODS - [:joins, :where, :order]).each do |method| value = r.send(:"#{method}_values") merged_relation.send(:"#{method}_values=", merged_relation.send(:"#{method}_values") + value) if value.present? end + order_value = r.order_values + if order_value.present? + if r.reorder_flag + merged_relation.order_values = order_value + else + merged_relation.order_values = merged_relation.order_values + order_value + end + end + merged_relation = merged_relation.joins(r.joins_values) merged_wheres = @where_values |