Skip to content

Commit

Permalink
Don't duplicate :order from scope and options, it makes mysql do extr…
Browse files Browse the repository at this point in the history
…a work
  • Loading branch information
jeremy committed Mar 11, 2009
1 parent cfde605 commit 19ad375
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,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
Expand Down
6 changes: 4 additions & 2 deletions activerecord/test/cases/method_scoping_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,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
Expand Down

0 comments on commit 19ad375

Please sign in to comment.