diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-03-10 23:11:05 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-03-10 23:11:05 -0700 |
commit | 19ad375e7afa99dc8bc5d859c478bae19c5ddc18 (patch) | |
tree | f5b1c4776ad408e9445b3c54fbe35588243ac0c2 /activerecord | |
parent | cfde60575a646549b47990befc037fa73a9dc393 (diff) | |
download | rails-19ad375e7afa99dc8bc5d859c478bae19c5ddc18.tar.gz rails-19ad375e7afa99dc8bc5d859c478bae19c5ddc18.tar.bz2 rails-19ad375e7afa99dc8bc5d859c478bae19c5ddc18.zip |
Don't duplicate :order from scope and options, it makes mysql do extra work
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/method_scoping_test.rb | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 4f39761672..62bdf0483a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1741,7 +1741,9 @@ module ActiveRecord #:nodoc: 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 diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 68a7017f86..3c34cdeade 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -378,8 +378,10 @@ class NestedScopingTest < ActiveRecord::TestCase 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 |