Open alexey-pelykh opened 5 months ago
upsert() of an Entity with lazy relation results in null column value
upsert()
upsert() can recognize value in lazy relation field named otherEntity.
otherEntity
upsert() looks for __otherEntity__ field.
__otherEntity__
await dataSource.entityManager.upsert( MyEntity, { externalReference: '...', otherEntity: Promise.resolve(otherEntity), }, );
with
@Entity() export class MyEntity { @Column({ unique: true }) @Index({ unique: true }) externalReference: string; @ManyToOne(() => MyOtherEntity, { lazy: true }) @JoinColumn() otherEntity: Promise<MyOtherEntity>; };
results in otherEntityId column to be empty because getLazyRelationsPromiseValue is not true thus it expects a __otherEntity__ field: https://github.com/typeorm/typeorm/blob/d184d8598c057ce8fa54815e669b567238f3a86e/src/metadata/RelationMetadata.ts#L474
otherEntityId
getLazyRelationsPromiseValue
true
No response
Yes, I have the time, but I don't know how to start. I would need guidance.
Working on PR that at least exposes the issue in #10531 10531
Issue description
upsert()
of an Entity with lazy relation results in null column valueExpected Behavior
upsert()
can recognize value in lazy relation field namedotherEntity
.Actual Behavior
upsert()
looks for__otherEntity__
field.Steps to reproduce
with
results in
otherEntityId
column to be empty becausegetLazyRelationsPromiseValue
is nottrue
thus it expects a__otherEntity__
field: https://github.com/typeorm/typeorm/blob/d184d8598c057ce8fa54815e669b567238f3a86e/src/metadata/RelationMetadata.ts#L474My Environment
Additional Context
No response
Relevant Database Driver(s)
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, but I don't know how to start. I would need guidance.