Repository navigation
fix: handle relation ids in nested embedded entities - #11942
Conversation
User descriptionDescription of changeThis PR fixes a Example entites: @Entity()
export class Parent {
@PrimaryGeneratedColumn()
id: number
@Column(() => Department)
department: Department
}
@Entity()
export class Account {
@PrimaryGeneratedColumn()
id: number
@Column()
name: string
}
export class Department {
@OneToOne(() => Account, { eager: true, cascade: true })
@JoinColumn()
account: Account
}What the change is intended to do: Why this change is needed: Closes #10578 Pull-Request Checklist
PR TypeBug fix Description
Diagram Walkthroughflowchart LR
A["Nested Embedded Entity<br/>with Relations"] -->|mapToProperty| B["Check if<br/>Intermediate Property<br/>Exists"]
B -->|Not Exists| C["Initialize as<br/>Empty Object"]
B -->|Exists| D["Recurse to<br/>Next Level"]
C --> D
D --> E["Successfully Map<br/>Relation IDs"]
|
| Relevant files | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Bug fix |
| ||||||||
| Tests |
|
commit: |
PR Code Suggestions ✨Latest suggestions up to 27e5b85
Previous suggestionsSuggestions up to commit 536254d
|
|||||||||||||||||||||
Code Review by Qodo
1. Array corruption risk in nested property mapping
|
536254d to
cab668a
Compare
PR Code Suggestions ✨No code suggestions found for the PR. |
|
Persistent review updated to latest commit cab668a |
|
Persistent review updated to latest commit 27e5b85 |

Description of change
This PR fixes a
TypeError: Cannot set properties of undefinedinRawSqlResultsToEntityTransformerthat occurred when mapping relation IDs to a property path nested within an embedded entity.Example entites:
What the change is intended to do:
The
mapToPropertyhelper function insidetransformRelationIdsnow checks if the intermediate property in the property path exists before recursing. If it doesn't exist, it initializes it as an empty object.Why this change is needed:
When an entity uses embedded entities with relations and TypeORM needs to load or update relation IDs (e.g., during persistence checks or with loadRelationIds: true), the transformer would crash if the embedded entity object hadn't been initialized yet in the transformation phase.
Closes #10578
Pull-Request Checklist
masterbranchFixes #10578tests/**.test.ts)docs/docs/**.md) (N/A)