diff options
author | Marcel Molina <marcel@vernix.org> | 2007-10-23 18:34:01 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2007-10-23 18:34:01 +0000 |
commit | c8b6b4821ff3f8135a22728bdf989e585a38d343 (patch) | |
tree | 71d2f4f0189f02c004adfc2eb7589b51427eddba /activerecord | |
parent | 6f559f871e9278aea65471f1ce31fab15536f56a (diff) | |
download | rails-c8b6b4821ff3f8135a22728bdf989e585a38d343.tar.gz rails-c8b6b4821ff3f8135a22728bdf989e585a38d343.tar.bz2 rails-c8b6b4821ff3f8135a22728bdf989e585a38d343.zip |
Limited eager loading no longer ignores scoped :order. Closes #9561 [danger, josh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 10 | ||||
-rw-r--r-- | activerecord/test/associations/eager_test.rb | 9 |
3 files changed, 15 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index c9f5534215..30ee1cec0b 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Limited eager loading no longer ignores scoped :order. Closes #9561 [danger, josh] + * Assigning an instance of a foreign class to a composed_of aggregate calls an optional conversion block. Refactor and simplify composed_of implementation. #6322 [brandon, Chris Cruft] * Assigning nil to a composed_of aggregate also sets its immediate value to nil. #9843 [Chris Cruft] diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0d440a75fd..b64b339781 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1293,12 +1293,10 @@ module ActiveRecord add_conditions!(sql, options[:conditions], scope) add_group!(sql, options[:group], scope) - if options[:order] - if is_distinct - connection.add_order_by_for_association_limiting!(sql, options) - else - add_order!(sql, options[:order], scope) - end + if options[:order] && is_distinct + connection.add_order_by_for_association_limiting!(sql, options) + else + add_order!(sql, options[:order], scope) end add_limit!(sql, options, scope) diff --git a/activerecord/test/associations/eager_test.rb b/activerecord/test/associations/eager_test.rb index fa632bdf69..2b02971238 100644 --- a/activerecord/test/associations/eager_test.rb +++ b/activerecord/test/associations/eager_test.rb @@ -250,6 +250,15 @@ class EagerAssociationTest < Test::Unit::TestCase assert_equal count, posts.size end end + + def test_eager_with_scoped_order_using_association_limiting_without_explicit_scope + posts_with_explicit_order = Post.find(:all, :conditions => 'comments.id', :include => :comments, :order => 'posts.id DESC', :limit => 2) + posts_with_scoped_order = Post.with_scope(:find => {:order => 'posts.id DESC'}) do + Post.find(:all, :conditions => 'comments.id', :include => :comments, :limit => 2) + end + assert_equal posts_with_explicit_order, posts_with_scoped_order + end + def test_eager_association_loading_with_habtm posts = Post.find(:all, :include => :categories, :order => "posts.id") assert_equal 2, posts[0].categories.size |