Repository navigation
fix: update RelationIdLoader to use DriverUtils.getAlias - #11228
Conversation
Update RelationIdLoader to use DriverUtils.getAlias to prevent aliases being possibly trimmed by database. Closes: #11227
WalkthroughUpdates RelationIdLoader to generate relation-ID mapping keys via DriverUtils.buildAlias. Adds a regression test suite (issue 11227) with two entities and a test verifying relation loading using a very long related-entity name under relationLoadStrategy: "query". Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test (issue-11227)
participant ORM as RelationIdLoader
participant DU as DriverUtils
participant DB as Database
Test->>DB: Insert SuperLongRelatedEntityNameDontAskWhy
Test->>DB: Insert SomeEntity with FK
Test->>ORM: Load SomeEntity with relation (strategy: "query")
ORM->>DU: buildAlias(driver, undefined, "<entity>_<relation>_<column>")
note right of DU: Dialect-aware alias/key construction
DU-->>ORM: alias/key
ORM->>DB: Query to resolve relation IDs using built alias
DB-->>ORM: Relation rows
ORM-->>Test: SomeEntity with related entity loaded
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
test/github-issues/11227/issue-11227.ts (2)
16-19: Option: broaden driver coverage (MySQL family also trims aliases).If CI has these drivers configured, consider adding them to strengthen coverage.
- enabledDrivers: ["postgres"], + enabledDrivers: ["postgres", "mysql", "mariadb"],
25-44: Optional: parallelize per-connection operations to speed up the test.Safe to parallelize since each connection hits an isolated DB.
- for (const connection of connections) { - const related = await connection - .getRepository(SuperLongRelatedEntityNameDontAskWhy) - .save({ name: "test" }) - const entity = await connection.getRepository(SomeEntity).save({ - superLongRelatedEntityNameDontAskWhy_id: related.id, - }) - const result = await connection.getRepository(SomeEntity).findOne({ - where: { id: entity.id }, - relations: { superLongRelatedEntityNameDontAskWhy: true }, - relationLoadStrategy: "query", - }) - expect(result?.superLongRelatedEntityNameDontAskWhy?.name).to.eq("test") - } + await Promise.all( + connections.map(async (connection) => { + const related = await connection + .getRepository(SuperLongRelatedEntityNameDontAskWhy) + .save({ name: "test" }) + const entity = await connection.getRepository(SomeEntity).save({ + superLongRelatedEntityNameDontAskWhy_id: related.id, + }) + const result = await connection.getRepository(SomeEntity).findOne({ + where: { id: entity.id }, + relations: { superLongRelatedEntityNameDontAskWhy: true }, + relationLoadStrategy: "query", + }) + expect(result?.superLongRelatedEntityNameDontAskWhy?.name).to.eq("test") + }), + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/query-builder/RelationIdLoader.ts(1 hunks)test/github-issues/11227/entity/SomeEntity.ts(1 hunks)test/github-issues/11227/entity/SuperLongRelatedEntityNameDontAskWhy.ts(1 hunks)test/github-issues/11227/issue-11227.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
test/github-issues/11227/issue-11227.ts (2)
src/connection/ConnectionManager.ts (1)
connections(16-18)test/utils/test-utils.ts (3)
createTestingConnections(388-482)reloadTestingDatabases(500-505)closeTestingConnections(487-495)
test/github-issues/11227/entity/SomeEntity.ts (5)
test/github-issues/11227/entity/SuperLongRelatedEntityNameDontAskWhy.ts (1)
Entity(3-10)src/decorator/columns/PrimaryGeneratedColumn.ts (1)
PrimaryGeneratedColumn(55-119)src/decorator/columns/Column.ts (1)
Column(134-220)src/decorator/relations/OneToOne.ts (1)
OneToOne(30-74)src/decorator/relations/JoinColumn.ts (1)
JoinColumn(31-48)
src/query-builder/RelationIdLoader.ts (1)
src/driver/DriverUtils.ts (1)
DriverUtils(8-297)
test/github-issues/11227/entity/SuperLongRelatedEntityNameDontAskWhy.ts (1)
test/github-issues/11227/entity/SomeEntity.ts (1)
Entity(10-21)
🔇 Additional comments (3)
test/github-issues/11227/issue-11227.ts (1)
12-45: Test adds the right regression coverage.Repro uses a long related-entity name and
relationLoadStrategy: "query"on Postgres—matches the failure mode and validates the fix.test/github-issues/11227/entity/SuperLongRelatedEntityNameDontAskWhy.ts (1)
3-10: LGTM: minimal entity for repro.Straightforward definition; nothing to change.
test/github-issues/11227/entity/SomeEntity.ts (1)
15-20: LGTM: explicit FK column + JoinColumn.This models the long-FK scenario cleanly for the test.
PR Code Suggestions ✨Latest suggestions up to a34a814
Previous suggestionsSuggestions up to commit 9938cc3
Suggestions
|
|||||||||||||||||||||||||||
PR Code Suggestions ✨
|
|||||||||
PR Code Suggestions ✨
|
|||||||||
|
/agentic_review |
PR Code Suggestions ✨No code suggestions found for the PR. |
Code Review by Qodo
1. Test added to github-issues directory
|
|
Persistent review updated to latest commit 6df10d1 |
PR Code Suggestions ✨No code suggestions found for the PR. |
|
Persistent review updated to latest commit 728b42f |
|
Persistent review updated to latest commit a34a814 |
Co-authored-by: gioboa <[email protected]> Co-authored-by: Naor Peled <[email protected]>

Update RelationIdLoader to use DriverUtils.getAlias to prevent aliases being possibly trimmed by database.
Closes: #11227
Description of change
Updates
RelationIdLoaderclass to useDriverUtils.getAliasto generate column aliases. This resolves issues with databases that have hard limit on column aliases such as PostgreSQL and MySQL.This is a follow up to #9380 which added
getAliasbut it missed a case forOneToOnerelations withrelationLoadStrategy: 'query'.Pull-Request Checklist
masterbranchnpm run formatto apply prettier formattingnpm run testpasses with this changeFixes #0000Summary by CodeRabbit
Bug Fixes
Tests