You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test: verify column names when using referencedColumnName in composite relations - #11883
The test uses an OR condition to check for correct SQL in both MySQL and PostgreSQL formats. However, this approach may pass even if one database generates incorrect SQL while the other is correct. Consider splitting into database-specific test cases or ensuring both formats are validated when applicable.
consthasCorrectJoin=sql.includes("LEFT JOIN `game` `game` ON `game`.`id`=`match`.`game_id` LEFT JOIN `participant` `participant` ON `participant`.`user_id`=`match`.`user_id` AND `participant`.`game_id`=`match`.`game_id`",)||sql.includes(`LEFT JOIN "game" "game" ON "game"."id"="match"."game_id" LEFT JOIN "participant" "participant" ON "participant"."user_id"="match"."user_id" AND "participant"."game_id"="match"."game_id"`,)expect(hasCorrectJoin).to.be.true
The order of JoinColumn array elements differs from the original issue. Original has game_id first, then user_id, but test has user_id first, then game_id. While this may not affect the bug reproduction, it's worth verifying this doesn't impact the test's ability to catch the specific caching issue mentioned.
Why: The suggestion correctly identifies that using (game) => game.id as the inverse relation property in @ManyToOne is unconventional and against TypeORM's documented usage, improving code clarity and maintainability.
Why: The suggestion correctly identifies that the inverse relation callback (game) => game.id in the @ManyToOne decorator is invalid, as it points to a primary key instead of a relation property. This creates incorrect entity metadata.
Low
General
Normalize whitespace in SQL assertion
Improve the SQL assertion by normalizing whitespace before checking for string inclusion, making the test less fragile to formatting changes.
+const normalizedSql = sql.replace(/\s+/g, ' ').trim()
const hasCorrectJoin =
- sql.includes(- "LEFT JOIN `game` `game` ON `game`.`id`=`match`.`game_id` LEFT JOIN `participant` `participant` ON `participant`.`user_id`=`match`.`user_id` AND `participant`.`game_id`=`match`.`game_id`",+ normalizedSql.includes(+ 'LEFT JOIN `game` `game` ON `game`.`id`=`match`.`game_id` LEFT JOIN `participant` `participant` ON `participant`.`user_id`=`match`.`user_id` AND `participant`.`game_id`=`match`.`game_id`',
) ||
- sql.includes(- `LEFT JOIN "game" "game" ON "game"."id"="match"."game_id" LEFT JOIN "participant" "participant" ON "participant"."user_id"="match"."user_id" AND "participant"."game_id"="match"."game_id"`,+ normalizedSql.includes(+ 'LEFT JOIN "game" "game" ON "game"."id"="match"."game_id" LEFT JOIN "participant" "participant" ON "participant"."user_id"="match"."user_id" AND "participant"."game_id"="match"."game_id"',
)
Suggestion importance[1-10]: 4
__
Why: The suggestion correctly points out that the test's SQL string matching is brittle due to its dependency on specific whitespace. Normalizing whitespace would make the test more robust against future formatting changes.
Low
Suggestions
Category
Suggestion
Impact
Possible issue
Fix incorrect ManyToOne relation callback
Correct the @ManyToOne relation on the game property by removing the invalid (game) => game.id callback, as it incorrectly specifies the inverse side of the relation.
Why: The suggestion correctly identifies that the (game) => game.id callback in the @ManyToOne decorator is semantically incorrect for defining an inverse relation, improving code correctness and adherence to TypeORM conventions.
Test includes both leftJoinAndSelect for game and participant relations
Requires further human verification:
Verify the test actually fails before the fix and passes after (to confirm it properly tests the bug)
Confirm the test runs specifically against PostgreSQL driver as mentioned in the issue
Validate that the SQL assertion correctly identifies the bug scenario
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review
Test Assertion Logic
The test uses an OR condition to check for correct SQL in both MySQL and PostgreSQL formats. However, this approach may pass even if one database generates incorrect SQL while the other is correct. Consider splitting into database-specific test cases or ensuring both formats are validated when applicable.
consthasCorrectJoin=sql.includes("LEFT JOIN `game` `game` ON `game`.`id`=`match`.`game_id` LEFT JOIN `participant` `participant` ON `participant`.`user_id`=`match`.`user_id` AND `participant`.`game_id`=`match`.`game_id`",)||sql.includes(`LEFT JOIN "game" "game" ON "game"."id"="match"."game_id" LEFT JOIN "participant" "participant" ON "participant"."user_id"="match"."user_id" AND "participant"."game_id"="match"."game_id"`,)expect(hasCorrectJoin).to.be.true
Order Difference
The order of JoinColumn array elements differs from the original issue. Original has game_id first, then user_id, but test has user_id first, then game_id. While this may not affect the bug reproduction, it's worth verifying this doesn't impact the test's ability to catch the specific caching issue mentioned.
The MySQL error unique constraint not found for FK_ for the entity participant appears if the order is changed. The order specified in JoinColumn[] and Participant.ts should be the same.
Correct the @ManyToOne relation on the game property by removing the invalid (game) => game.id callback, as it incorrectly specifies the inverse side of the relation.
Why: The suggestion correctly identifies that the (game) => game.id callback in the @ManyToOne decorator is semantically incorrect for defining an inverse relation, improving code correctness and adherence to TypeORM conventions.
Qodo reviewed your code and found no material issues that require review
Cprakhar
changed the title
test: add test for issue #7242
test: add tests to verify that correct column names are generated when using referencedColumnName in composite relations
Jan 14, 2026
Cprakhar
changed the title
test: add tests to verify that correct column names are generated when using referencedColumnName in composite relations
test: add tests to verify that correct column names are generated when using referencedColumnName in composite relations
Jan 14, 2026
gioboa
changed the title
test: add tests to verify that correct column names are generated when using referencedColumnName in composite relations
test: verify column names when using referencedColumnName in composite relations
Jan 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #7242
Added a test that shows that issue #7242 is resolved.