I'm trying to delete some records from a entity, but typeorm is not using the @Column definition os the entity, thus performing a invalid sql:
@Entity('table')
export class TableEntity implements Table {
@Column({ name: 'user_id' })
@PrimaryColumn()
userId: number;
...
}
this.repository.delete({
userId: 1
})
DELETE FROM "table" WHERE "userId" = $1
and not
DELETE FROM "table" where "user_id" = $1
as I expected. Why?
This issue is probably long time solved by the author, but for those who ended up here from Google like me:
@PrimaryColumn() resets information previously provided by @Column().
So, instead of writing
@Column({ name: 'user_id' })
@PrimaryColumn()
userId: number;
one should write
@PrimaryColumn({ name: 'user_id' })
userId: number;
Have a great coding time guys!