Created
August 29, 2010 22:20
-
-
Save lifo/556759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb | |
index e7e5f26..61cac59 100644 | |
--- a/activerecord/lib/active_record/relation/spawn_methods.rb | |
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb | |
@@ -6,7 +6,7 @@ module ActiveRecord | |
merged_relation = clone | |
return merged_relation unless r | |
- ((Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS) - [:joins, :where]).each do |method| | |
+ ((Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS) - [:joins, :where, :order]).each do |method| | |
value = r.send(:"#{method}_values") | |
unless value.empty? | |
if method == :includes | |
@@ -17,6 +17,10 @@ module ActiveRecord | |
end | |
end | |
+ if (order_values = r.order_values).present? | |
+ merged_relation.order_values = order_values + merged_relation.order_values | |
+ end | |
+ | |
merged_relation = merged_relation.joins(r.joins_values) | |
merged_wheres = @where_values | |
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb | |
index aa75aa2..d9fdb10 100644 | |
--- a/activerecord/test/cases/relations_test.rb | |
+++ b/activerecord/test/cases/relations_test.rb | |
@@ -667,4 +667,8 @@ class RelationTest < ActiveRecord::TestCase | |
def test_relations_limit_with_conditions_or_limit | |
assert_equal Post.limit(2).size, Post.limit(2).all.size | |
end | |
+ | |
+ def test_chaining_scopes_using_order_method_is_equivalent_to_chaining_scopes_using_scope_with_that_order | |
+ assert_equal Post.order("id").order("comments_count DESC").order_values, Post.order("id").ranked_by_comments.order_values | |
+ end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment