Repository navigation
fix: eager load relation strategy - #11326
Conversation
…trategy and some other related features
…ed the wrong relation names when not querying the database
…load validation when link relations with query strategy. fixed by validating type before compare, but the best would be fixing in cockroachdb result
…oach driver from returning wrong id type in getRawMany
…eager-load-relation-strategy
…-relation-strategy
…ecting the loadEagerRelations query option
Fixed nested eager relations ignoring loadEagerRelations optionI fixed a bug where nested eager relations were being loaded regardless of the The fix ensures that the I'll check if this error is occurring during |
…9006-eager-load-relation-strategy
commit: |
gioboa
left a comment
There was a problem hiding this comment.
Can I ask you to fix the issues with formatting please?
Fixed the issues. Let me know if there is anything else I could do. |
Fixed. Sry about that. |
199162b to
f2150bd
Compare
|
Persistent review updated to latest commit f2150bd |
|
Persistent review updated to latest commit d81738d |
|
Persistent review updated to latest commit 246c351 |
246c351 to
0505163
Compare
Review Summary by QodoImplement eager relation loading via query strategy with circular dependency handling
WalkthroughsDescription• Implement relationLoadStrategy: 'query' to load eager relations via separate queries instead of joins • Add cycle detection for circular eager relation chains to prevent infinite recursion • Fix type coercion issues in relation ID loading for database drivers like CockroachDB • Respect loadEagerRelations option in relation loading strategies • Add comprehensive test coverage for query-based relation loading strategies Diagramflowchart LR
A["relationLoadStrategy: query"] --> B["SelectQueryBuilder"]
B --> C["RelationLoader.applyEagerRelations"]
C --> D["concatRelationMetadata for query strategy"]
D --> E["QueryStrategyRelationIdLoader"]
E --> F["RelationIdLoader with type coercion"]
F --> G["prepareHydratedValue for driver compatibility"]
B --> H["eagerLoadChain cycle detection"]
H --> I["Prevent infinite recursion in circular relations"]
File Changes1. src/query-builder/RelationIdLoader.ts
|
|
|
Persistent review updated to latest commit 0505163 |
|
A few more fixes pushed after running CI and SonarQube analysis: Bug fixes:
Code quality (SonarQube):
|
Code Review by Qodo
1. Eager loading docs now inaccurate
|
Code Review by Qodo
1. Missing docs for query strategy
|
|
Hi @pkuczynski, thank you for the time and effort you put into reviewing and improving this PR. I reviewed the changes and noticed two points that I think are worth considering: The way the tests were originally implemented reflects the nature of the issue: eager loading was working, but not in the correct way. I considered it important to use a spy to map the internal flow so the test would fail without the fix and pass after the fix. Looking at the new test, I believe this behavior may no longer be covered, and the maintainers can confirm whether this change introduces any issues. Regarding the eager-load loop check, at the time I was not able to reproduce a case where the loop actually occurred, so I assumed there was already some internal process preventing those scenarios. For that reason, I did not prioritize implementing an additional safeguard. I still believe there is another safeguard preventing the loop; if I find it, I will add a comment documenting it. I’m currently working on a robust project running on a fork with these fixes. I will apply the latest changes there and test them in staging to verify whether any unusual behavior appears. If anything remaining comes up, I’ll open a follow-up PR referencing this one and addressing the issues found. Thanks again for your attention. Should any further changes or fixes be needed, I remain available to help, please feel free to reach out. |



Description of change
Fixes #9006
This PR addresses the issue where the
relationLoadStrategy: 'query'option did not split the entire query into multiple queries as expected. The functionality of loading eager relations with new queries instead of joins was not implemented.Changes Made
RelationLoadermethods that should or should not load the eager relations according to the query optionloadEagerRelations. This has been added.Ideas for Future Improvements
loadStrategyor use the existingeageras a string to specify whether eager loading should be performed as a join or query. This would provide detailed control over all eager loads, significantly improving performance.Pull-Request Checklist
npm run formatto apply prettier formattingnpm run testpasses with this change