Permalink
Browse files

Correctly pass joins when creating a JoinDependency.

Backport of #14834 to 4-0-stable
  • Loading branch information...
1 parent 3026f42 commit d49e6803e828d5b7c7986491d873f61593cf7435 @al2o3cr al2o3cr committed May 28, 2014
@@ -60,8 +60,10 @@ def initial_count_for(name)
join.left.downcase.scan(
/join(?:\s+\w+)?\s+(\S+\s+)?#{quoted_name}\son/
).size
- else
+ elsif join.respond_to? :left
join.left.table_name == name ? 1 : 0
+ else
+ 0
end
end
@@ -212,7 +212,7 @@ def find_with_associations
def construct_join_dependency_for_association_find
including = (eager_load_values + includes_values).uniq
- ActiveRecord::Associations::JoinDependency.new(@klass, including, [])
+ ActiveRecord::Associations::JoinDependency.new(@klass, including, joins_values)
end
def construct_relation_for_association_calculations
@@ -126,4 +126,15 @@ def test_find_with_conditions_on_through_reflection
categories = author.categories.includes(:special_categorizations).references(:special_categorizations).to_a
assert_equal 2, categories.size
end
+
+
+ test "the correct records are loaded when including an aliased association" do
+ author = Author.create! name: "Jon"
+ author.categories.create! name: 'Not Special'
+ author.special_categories.create! name: 'Special'
+
+ categories = author.categories.eager_load(:special_categorizations).order(:name).to_a
+ assert_equal 0, categories.first.special_categorizations.size
+ assert_equal 1, categories.second.special_categorizations.size
+ end
end

0 comments on commit d49e680

Please sign in to comment.