Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit c8b6b4821ff3f8135a22728bdf989e585a38d343 1 parent 6f559f8
Marcel Molina authored
View
2  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]
View
10 activerecord/lib/active_record/associations.rb
@@ -1293,12 +1293,10 @@ def construct_finder_sql_for_association_limiting(options, join_dependency)
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)
View
9 activerecord/test/associations/eager_test.rb
@@ -250,6 +250,15 @@ def test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the
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
Please sign in to comment.
Something went wrong with that request. Please try again.