aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-03-10 23:11:05 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-03-10 23:11:05 -0700
commit19ad375e7afa99dc8bc5d859c478bae19c5ddc18 (patch)
treef5b1c4776ad408e9445b3c54fbe35588243ac0c2 /activerecord
parentcfde60575a646549b47990befc037fa73a9dc393 (diff)
downloadrails-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-xactiverecord/lib/active_record/base.rb4
-rw-r--r--activerecord/test/cases/method_scoping_test.rb6
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