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
Replace the .constructor === Object check with a more robust prototype-based check (Object.getPrototypeOf) to reliably detect plain objects and avoid potential runtime errors with edge cases like Object.create(null).
!(embeddedObject[this.propertyName] instanceof Date) &&
(!this.transformer ||
- embeddedObject[this.propertyName].constructor ===- Object)+ (() => {+ const v = embeddedObject[this.propertyName]+ const proto = Object.getPrototypeOf(v)+ return proto === Object.prototype || proto === null+ })())
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that using constructor === Object is not a robust way to check for plain objects and proposes a more reliable prototype-based check, improving the code's resilience to edge cases.
Low
Make object checks runtime-safe
Replace the .constructor === Object check with a safer, prototype-based check to prevent unexpected failures or incorrect behavior when handling object values during updates.
if (
column.referencedColumn &&
typeof value === "object" &&
!(value instanceof Date) &&
value !== null &&
!Buffer.isBuffer(value) &&
(!column.transformer ||
- value.constructor === Object)+ (() => {+ const proto = Object.getPrototypeOf(value)+ return proto === Object.prototype || proto === null+ })())
) {
- value =- column.referencedColumn.getEntityValue(value)+ value = column.referencedColumn.getEntityValue(value)
}
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that using constructor === Object is not a robust way to check for plain objects and proposes a more reliable prototype-based check, improving the code's resilience to edge cases.
Refine the logic for handling transformed foreign keys to allow foreign key value extraction from a related entity object. The current implementation incorrectly blocks this when a value transformer is present.
Why: The suggestion correctly identifies that the PR's change, while fixing one issue, introduces a new bug by preventing foreign key extraction from a full entity object if the column has a transformer. The proposed fix is robust and handles both cases correctly.
High
Refine logic for embedded transformed FKs
Refine the logic for handling transformed foreign keys within embedded entities. The current implementation incorrectly blocks foreign key extraction when a value transformer is present on a column inside an embed.
Why: This suggestion correctly applies the same critical logic fix from the first suggestion to the code path for embedded entities. This ensures consistent and correct behavior for transformed foreign keys within embeds.
The PR fixes FK value-object handling in ColumnMetadata.getEntityValue, but UpdateQueryBuilder still
extracts referencedColumn values from any object and then skips preparePersistentValue, so
transformed FK UPDATEs can still yield undefined/untransformed parameters.
ColumnMetadata now avoids referencedColumn extraction when a transformer exists and then applies
transformer.to when requested, enabling value-object FK insert/load. UpdateQueryBuilder, however,
still forces referencedColumn.getEntityValue(value) for any object value and bypasses
driver.preparePersistentValue (which is where transformers are applied), so UPDATEs can still fail
for the same value-object FK scenario.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`UpdateQueryBuilder` still treats any object value for a FK column (`column.referencedColumn`) as an entity/id-map and replaces it with `referencedColumn.getEntityValue(value)`, *skipping* `driver.preparePersistentValue(...)`. For transformed FK value objects (e.g., `AuthorId`), this can produce `undefined` (because the object lacks the referenced column property) and also bypass transformer application.
### Issue Context
This PR changed `ColumnMetadata.getEntityValue` to skip referenced id extraction when `this.transformer` is present, which makes inserting/loading FK value objects work. UPDATE query building is still inconsistent.
### Fix Focus Areas
- src/query-builder/UpdateQueryBuilder.ts[537-554]
- src/metadata/ColumnMetadata.ts[855-895]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Transformer guard too broad 🐞 Bug✓ Correctness
Description
Gating referencedColumn extraction on !this.transformer fixes passing value objects directly (as
in the new test) but can break passing an entity/id-map object (e.g. { id: AuthorId(...) }) into a
transformed FK column, because the transformer will now receive the whole object instead of the
extracted id.
ColumnMetadata’s FK-object handling previously extracted referenced ids from object values; the PR
now disables that path whenever a transformer exists. The codebase documents the pattern of
providing object values for relational columns and extracting the referenced id, so this change can
break that pattern specifically when a transformer is present (transformer.to gets an unexpected
object shape). The new test demonstrates the intended new-supported case (value object directly).
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
The new `!this.transformer` guard prevents referencedColumn extraction for **all** object inputs on FK columns when a transformer exists. This fixes value-object FK inputs (e.g., `authorId: new AuthorId(...)`) but can break existing patterns where the FK property is set to an entity or id-map object (e.g., `authorId: { id: new AuthorId(...) }`), because the transformer will receive the whole object rather than the extracted id.
### Issue Context
TypeORM has documented/implemented behavior to extract referenced ids from object inputs for relational columns (see InsertQueryBuilder comment). With the current change, that behavior is disabled whenever `transformer` is set.
### Fix Focus Areas
- src/metadata/ColumnMetadata.ts[814-842]
- src/metadata/ColumnMetadata.ts[855-883]
- src/query-builder/InsertQueryBuilder.ts[1537-1542]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ⓘ The new review experience is currently in Beta. Learn more
1. Plain-object check inconsistent 🐞 Bug⛯ Reliability⭐ New
Description
The new value.constructor === Object plain-object check does not handle null-prototype objects
(e.g., Object.create(null)) and is inconsistent with existing repo logic, potentially changing FK
extraction behavior in edge cases.
UpdateQueryBuilder adopts (!column.transformer || value.constructor === Object) which treats
Object.create(null) values as non-plain (constructor is undefined). The repo already has a
plain-object check that explicitly supports this case (`!item.constructor || item.constructor ===
Object`), indicating the new check is a weaker/inconsistent variant.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`value.constructor === Object` fails for null-prototype objects and is inconsistent with the repository’s existing plain-object logic.
### Issue Context
The repo already treats `Object.create(null)` as a plain object in `OrmUtils`.
### Fix Focus Areas
- src/query-builder/UpdateQueryBuilder.ts[537-550]
- src/metadata/ColumnMetadata.ts[826-838]
- src/metadata/ColumnMetadata.ts[869-879]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
The PR fixes FK value-object handling in ColumnMetadata.getEntityValue, but UpdateQueryBuilder still
extracts referencedColumn values from any object and then skips preparePersistentValue, so
transformed FK UPDATEs can still yield undefined/untransformed parameters.
ColumnMetadata now avoids referencedColumn extraction when a transformer exists and then applies
transformer.to when requested, enabling value-object FK insert/load. UpdateQueryBuilder, however,
still forces referencedColumn.getEntityValue(value) for any object value and bypasses
driver.preparePersistentValue (which is where transformers are applied), so UPDATEs can still fail
for the same value-object FK scenario.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`UpdateQueryBuilder` still treats any object value for a FK column (`column.referencedColumn`) as an entity/id-map and replaces it with `referencedColumn.getEntityValue(value)`, *skipping* `driver.preparePersistentValue(...)`. For transformed FK value objects (e.g., `AuthorId`), this can produce `undefined` (because the object lacks the referenced column property) and also bypass transformer application.
### Issue Context
This PR changed `ColumnMetadata.getEntityValue` to skip referenced id extraction when `this.transformer` is present, which makes inserting/loading FK value objects work. UPDATE query building is still inconsistent.
### Fix Focus Areas
- src/query-builder/UpdateQueryBuilder.ts[537-554]
- src/metadata/ColumnMetadata.ts[855-895]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. Transformer guard too broad 🐞 Bug✓ Correctness
Description
Gating referencedColumn extraction on !this.transformer fixes passing value objects directly (as
in the new test) but can break passing an entity/id-map object (e.g. { id: AuthorId(...) }) into a
transformed FK column, because the transformer will now receive the whole object instead of the
extracted id.
ColumnMetadata’s FK-object handling previously extracted referenced ids from object values; the PR
now disables that path whenever a transformer exists. The codebase documents the pattern of
providing object values for relational columns and extracting the referenced id, so this change can
break that pattern specifically when a transformer is present (transformer.to gets an unexpected
object shape). The new test demonstrates the intended new-supported case (value object directly).
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The new `!this.transformer` guard prevents referencedColumn extraction for **all** object inputs on FK columns when a transformer exists. This fixes value-object FK inputs (e.g., `authorId: new AuthorId(...)`) but can break existing patterns where the FK property is set to an entity or id-map object (e.g., `authorId: { id: new AuthorId(...) }`), because the transformer will receive the whole object rather than the extracted id.
### Issue Context
TypeORM has documented/implemented behavior to extract referenced ids from object inputs for relational columns (see InsertQueryBuilder comment). With the current change, that behavior is disabled whenever `transformer` is set.
### Fix Focus Areas
- src/metadata/ColumnMetadata.ts[814-842]
- src/metadata/ColumnMetadata.ts[855-883]
- src/query-builder/InsertQueryBuilder.ts[1537-1542]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ⓘ The new review experience is currently in Beta. Learn more
coverage: 81.416% (-0.003%) from 81.419%
when pulling 99a40ce on gioboa:fix/9565
into f47246c on typeorm:master.
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 #9565
Description of change
Pull-Request Checklist
masterbranchFixes #00000tests/**.test.ts)docs/docs/**.md)