aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-11-07 00:18:07 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-11-07 00:18:07 +0000
commita3dba1ed7cabc53d474c37eba973d617445b389e (patch)
tree91a0d986979c3210237b1dd75573aa157bcc48fb
parenta7d0e0e011928a77abb8630ce61f219ec80e86f4 (diff)
downloadrails-a3dba1ed7cabc53d474c37eba973d617445b389e.tar.gz
rails-a3dba1ed7cabc53d474c37eba973d617445b389e.tar.bz2
rails-a3dba1ed7cabc53d474c37eba973d617445b389e.zip
Find with :include respects scoped :order. Closes #5850.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5445 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb2
-rwxr-xr-xactiverecord/test/base_test.rb10
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 606f87f678..6c0dce4309 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Find with :include respects scoped :order. #5850
+
* Support nil and Array in :conditions => { attr => value } hashes. #6548 [Assaf, Jeremy Kemper]
find(:all, :conditions => { :topic_id => [1, 2, 3], :last_read => nil }
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 8a1b6ca933..f9713199d5 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1169,8 +1169,8 @@ module ActiveRecord
add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
sql << "GROUP BY #{options[:group]} " if options[:group]
- sql << "ORDER BY #{options[:order]} " if options[:order]
+ add_order!(sql, options[:order])
add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections)
return sanitize_sql(sql)
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 27bfdfb72f..bddfa882b9 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1312,6 +1312,16 @@ class BasicsTest < Test::Unit::TestCase
assert_equal 2, topics.first.id
end
+ def test_scoped_find_order_including_has_many_association
+ developers = Developer.with_scope(:find => { :order => 'developers.salary DESC', :include => :projects }) do
+ Developer.find(:all)
+ end
+ assert developers.size >= 2
+ for i in 1...developers.size
+ assert developers[i-1].salary >= developers[i].salary
+ end
+ end
+
def test_base_class
assert LoosePerson.abstract_class?
assert !LooseDescendant.abstract_class?