javascript - 唯一键没有像 postgres 中的其他字段一样更新
问题描述
我正在开发一个 NestJs 项目,一切似乎都很好,直到我尝试更新,我发现我尝试更改为另一个 UUID 的 UUID 来自不同的表并没有更新。虽然我没有收到任何错误,但很明显有些事情我做得不对。下面是代码列表:
consumablePack.repository.ts
async updateConsumablePack(
id: string,
updateConsumablePackDto: UpdateConsumablePackDto
): Promise<ConsumablePack> {
const { product, quantity, unit, productId } = updateConsumablePackDto;
const consumablePack = new ConsumablePack();
consumablePack.product = product;
consumablePack.quantity = quantity;
consumablePack.unit = unit;
consumablePack['_productId'] = productId;
console.log('====================================');
console.log(Product);
console.log('====================================');
return this.save({ id, ...consumablePack });
}
consumablePack.entity.ts
@Entity()
export class ConsumablePack {
@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToOne(() => Product, (product) => product.id, {
cascade: ['insert', 'update'],
})
@JoinColumn()
product: Product;
@Column({ nullable: true })
quantity: number;
@Column({
type: 'enum',
enum: UnitOptions,
default: UnitOptions.PIECE,
})
unit: UnitOptions;
}
consumablePack.dto.ts
export class CreateConsumablePackDto {
@IsUUID()
productId: string;
product: Product;
@IsNotEmpty()
quantity: number;
@IsIn(['PIECE', 'CARTON', 'PACK'])
unit: UnitOptions;
}
export class UpdateConsumablePackDto {
productId: string;
product: Product;
quantity: number;
@IsIn(['PIECE', 'CARTON', 'PACK'])
unit: UnitOptions;
}
解决方案
推荐阅读
- excel - Google 表格到 Excel 的转换 - 将“”视为零
- graphql - 为什么 Hasura 在 beta8 中启动时会出现“以下根字段重复”的错误?
- react-native - yarn --version 在 package.json 中返回 1.15.2 但 1.19.1
- reactjs - Windows 10 上的 npm 相关错误
- javascript - Bootstrap carousel next/prev 方法强制它更快地自动播放
- javascript - WebGL 着色器闪烁
- audiokit - AudioKit,从参考文件创建 eq
- mongodb - 如何在mongodb中更新对象数组
- python - 如何在 Python 中为复杂的 __init__ 使用数据类?
- machine-learning - 区分猫狗的迁移学习实践