mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make referencing an included item trigger eager loading
This commit is contained in:
parent
4c4760a619
commit
4429f16c0a
2 changed files with 13 additions and 1 deletions
|
@ -521,7 +521,8 @@ module ActiveRecord
|
|||
# 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 @@ class RelationTest < ActiveRecord::TestCase
|
|||
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 a new issue