Entity lacks primary column properties in afterRemove() subscription.
See original GitHub issueIssue type: [x] bug report
Database system/driver:
[x] postgres
TypeORM version:
[x] latest
Steps to reproduce or a small repository showing the problem:
Say we have User
entity with login
as primary column and Proposal
entity with id
primary column.
Then we define the following Rating
entity as a join table for those ones:
@Entity()
export class Rating {
@ManyToOne(_type => User, { primary: true, onDelete: 'CASCADE' })
@JoinColumn({ name: 'raterLogin' })
rater!: Promise<User>;
@ManyToOne(_type => Proposal, { primary: true, onDelete: 'CASCADE' })
@JoinColumn({ name: 'proposalId' })
proposal!: Promise<Proposal>;
@PrimaryColumn()
raterLogin!: string;
@PrimaryColumn()
proposalId!: number;
@Column()
liked!: boolean;
}
When we define a subscriber for Rating
and call ratingRepo.remove(ratingEntity)
, then afterRemove()
method gets called with ratingEntity
as one of the arguments. But why do its primary column properties raterLogin
and proposalId
have value undefined
? You may check it in the debugger local variables window:
Why do we need to assemble the entity by parts and get primary columns from e.entityId
? Why did you define TypeScript
type for this event to be full-fledged Entity | undefined
instead of Partial<Entity> | undefined
if you decided to remove primary columns?
Other methods (afterInsert()
and afterUpdate()
) get entities with live primary columns in place.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top GitHub Comments
I’m facing the same issue and found out that
RemoveEvent<Entity>
has anentityId
fieldThanks. Superhacky but I did the same. I created a shadow variable to store the primary key. lol.