Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Eager loading respects explicit :joins. Closes #9496.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7494 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b8657089f289e2b3a9d5c383516e951012b2bec2 1 parent a6083b8
@jeremy jeremy authored
View
2  activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Eager loading respects explicit :joins. #9496 [dasil003]
+
* Extract Firebird, FronBase, and OpenBase adapters into gems. #9508, #9509, #9510 [Jeremy Kemper]
* RubyGem database adapters: expects a gem named activerecord-<database>-adapter with active_record/connection_adapters/<database>_adapter.rb in its load path. [Jeremy Kemper]
View
2  activerecord/lib/active_record/associations.rb
@@ -1266,7 +1266,7 @@ def select_limited_ids_list(options, join_dependency)
def construct_finder_sql_for_association_limiting(options, join_dependency)
scope = scope(:find)
- is_distinct = include_eager_conditions?(options) || include_eager_order?(options)
+ is_distinct = !options[:joins].blank? || include_eager_conditions?(options) || include_eager_order?(options)
sql = "SELECT "
if is_distinct
sql << connection.distinct("#{table_name}.#{primary_key}", options[:order])
View
5 activerecord/test/associations/eager_test.rb
@@ -103,6 +103,11 @@ def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_mult
assert_equal [2], posts.collect { |p| p.id }
end
+ def test_eager_association_loading_with_explicit_join
+ posts = Post.find(:all, :include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id')
+ assert_equal 1, posts.length
+ end
+
def test_eager_with_has_many_through
posts_with_comments = people(:michael).posts.find(:all, :include => :comments)
posts_with_author = people(:michael).posts.find(:all, :include => :author )
Please sign in to comment.
Something went wrong with that request. Please try again.