Make referencing an included item trigger eager loading
This commit is contained in:
parent
4c4760a619
commit
4429f16c0a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user