【发布时间】:2021-07-16 14:47:07
【问题描述】:
我有以下实体:
@Entity({ name: 'user' })
export class UserEntity extends BasicEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({
nullable: false,
unique: true,
})
login: string;
}
@Entity({ name: 'wallet' })
export class WalletEntity extends BasicEntity {
@PrimaryGeneratedColumn()
id: number;
@ManyToOne(() => UserEntity)
@JoinColumn({ name: 'user_id' })
user: UserEntity;
@Column({
name: 'address',
type: 'text',
})
address: string;
}
所以,钱包表是这样的:
-------------------------
id | user_id | address
-------------------------
1 | 1 | 0x12
-------------------------
2 | 43 | 0x10
我喜欢通过 Repository api 更新 wallet 实体。但问题是,我不能只是:
WalletRepository.save({ address: '0x12', userId: 2 })
因为 Typescript 给我一个错误,所以 userId 应该是 userEntity,而不是数字。但我想更新一个关系列。那么有没有办法更新呢?
【问题讨论】:
标签: node.js typescript postgresql nestjs typeorm