Skip to content

Fix include parser dropping sibling sub-includes under a shared intermediate relationship#127

Merged
lucacorti merged 1 commit intolucacorti:mainfrom
albertoforcato:main
Mar 20, 2026
Merged

Fix include parser dropping sibling sub-includes under a shared intermediate relationship#127
lucacorti merged 1 commit intolucacorti:mainfrom
albertoforcato:main

Conversation

@albertoforcato
Copy link
Copy Markdown
Contributor

When two or more include paths share the same intermediate relationship node (e.g. bestComments.user.company and bestComments.user.topPosts), the parser processes each path separately and accumulates results one by one with Keyword.merge/2. Because both paths produce the same top-level key (best_comments: [user: [...]]), the second merge silently overwrites the first, dropping earlier sub-preloads from the Ecto preload list.

The fix replaces the shallow Keyword.merge/2 with a recursive deep_merge/2 that combines nested keyword lists instead of overwriting them, so every leaf preload is retained regardless of ordering or nesting depth.

Added four tests to parse_include/2 covering:

  • two siblings under the same parent
  • siblings when the intermediate node is also requested explicitly
  • four paths sharing intermediate nodes at multiple depths

@lucacorti
Copy link
Copy Markdown
Owner

This is great, thank you!

@lucacorti lucacorti merged commit 3310c1c into lucacorti:main Mar 20, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants