Permalink
Browse files

Don't duplicate :order from scope and options, it makes mysql do extr…

…a work
  • Loading branch information...
1 parent b6ad4bd commit 5f95347af583d2e2a67631da02e0293679991612 @jeremy jeremy committed Mar 11, 2009
Showing with 7 additions and 3 deletions.
  1. +3 −1 activerecord/lib/active_record/base.rb
  2. +4 −2 activerecord/test/cases/method_scoping_test.rb
@@ -1678,7 +1678,9 @@ def add_order!(sql, order, scope = :auto)
scoped_order = scope[:order] if scope
if order
sql << " ORDER BY #{order}"
- sql << ", #{scoped_order}" if scoped_order
+ if scoped_order && scoped_order != order
+ sql << ", #{scoped_order}"
+ end
else
sql << " ORDER BY #{scoped_order}" if scoped_order
end
@@ -341,8 +341,10 @@ def test_three_level_nested_exclusive_scoped_find
def test_merged_scoped_find
poor_jamis = developers(:poor_jamis)
Developer.with_scope(:find => { :conditions => "salary < 100000" }) do
- Developer.with_scope(:find => { :offset => 1 }) do
- assert_equal(poor_jamis, Developer.find(:first, :order => 'id asc'))
+ Developer.with_scope(:find => { :offset => 1, :order => 'id asc' }) do
+ assert_sql /ORDER BY id asc / do
+ assert_equal(poor_jamis, Developer.find(:first, :order => 'id asc'))
+ end
end
end
end

0 comments on commit 5f95347

Please sign in to comment.