Eager loading respects explicit :joins. Closes #9496.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7494 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper
2007-09-15 23:50:12 +00:00
parent a6083b86d1
commit b8657089f2
3 changed files with 8 additions and 1 deletions

View File

@@ -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 File

@@ -1266,7 +1266,7 @@ module ActiveRecord
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 File

@@ -103,6 +103,11 @@ class EagerAssociationTest < Test::Unit::TestCase
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 )