Make referencing an included item trigger eager loading

This commit is contained in:
Jon Leighton 2012-01-14 00:17:39 +00:00
parent 4c4760a619
commit 4429f16c0a
2 changed files with 13 additions and 1 deletions

@ -521,7 +521,8 @@ def references_eager_loaded_tables?
# always convert table names to downcase as in Oracle quoted table names are in uppercase
joined_tables = joined_tables.flatten.compact.map { |t| t.downcase }.uniq
(tables_in_string(to_sql) - joined_tables).any?
(tables_in_string(to_sql) - joined_tables).any? ||
(includes_values & references_values).any?
end
def tables_in_string(string)

@ -1164,4 +1164,15 @@ def test_uniq
end
assert_equal ['Foo', 'Foo'], query.uniq(true).uniq(false).map(&:name)
end
def test_references_triggers_eager_loading
scope = Post.includes(:comments)
assert !scope.eager_loading?
assert scope.references(:comments).eager_loading?
end
def test_references_doesnt_trigger_eager_loading_if_reference_not_included
scope = Post.references(:comments)
assert !scope.eager_loading?
end
end