【发布时间】:2020-04-22 07:33:19
【问题描述】:
问题:
装饰 @PrimaryGeneratedColumn() 的实体 id 可在 put 请求上覆盖。
预期行为:
用@PrimaryGeneratedColumn()装饰的id不会更新。
重现步骤:
- 使用此帖子请求创建一个条目:
curl --location --request POST 'https://q6zre.sse.codesandbox.io/tests' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "acme"}'
- 从响应中复制
id,添加到put请求的url中,并在body中添加一个随机的wishedId:
curl --location --request PUT 'https://q6zre.sse.codesandbox.io/tests/{id}' \
--header 'Content-Type: application/json' \
--data-raw '{"id": "{wishedId}"}'
条目更新为wishedId。
工作示例:https://codesandbox.io/s/github/desirelabs/nest-typeorm
有什么办法可以防止这种情况发生吗? 谢谢
【问题讨论】: