Skip to content

Commit

Permalink
Merge pull request #52619 from fatkodima/eager-load-nil-associations
Browse files Browse the repository at this point in the history
Allow to eager load nested nil associations
  • Loading branch information
byroot authored and rafaelfranca committed Aug 16, 2024
1 parent dbc560d commit 62abd09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def self.walk_tree(associations, hash)
when Hash
associations.each do |k, v|
cache = hash[k] ||= {}
walk_tree v, cache
walk_tree v, cache if v
end
else
raise ConfigurationError, associations.inspect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ def test_eager_association_loading_with_join_for_count
assert_queries(3) { authors.to_a }
end

def test_eager_association_loading_with_nil_associations
authors = Author.includes(nil).to_a
assert_equal 3, authors.size

authors = Author.includes([:posts, nil]).to_a
assert_equal 3, authors.size

authors = Author.includes(posts: nil).to_a
assert_equal 3, authors.size
end

def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations
authors = Author.all.merge!(includes: { posts: [:comments, :categorizations] }, order: "authors.id").to_a
assert_equal 3, authors.size
Expand Down

0 comments on commit 62abd09

Please sign in to comment.