typescript - 为什么在 typeorm 和 nestjs 中 InsertResult 为空
问题描述
当我尝试将一些数据插入存储库时。
const newChild = await queryRunner.manager.insert<Child>('child', child);
_height.childId = newChild.generatedMaps[0].id;
我遇到了以下错误。
error TypeError: Cannot read property 'id' of undefined
我检查了InsertResult
console.log(newChild);
InsertResult {
identifiers: [],
generatedMaps: [],
raw: OkPacket {
fieldCount: 0,
affectedRows: 1,
insertId: 7,
serverStatus: 3,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0
}
}
似乎identifiers
是空的。
这可能是什么原因?
如果有人有意见,请告诉我。
谢谢
解决方案
对我来说,需要在 typeorm 配置中设置“实体”属性。
这样的事情解决了我的问题:
ormconfig.json
{
...
"username": "root",
"password": "admin",
"database": "test",
...
"entities": [
"dist/**/entity/**/*.js"
],
推荐阅读
- powershell - Do-Until 循环询问两次值
- elixir - Guardian.Plug.EnsurePermissions 无法识别
- android - 每次禁用设置权限时重新启动活动
- css - Gulp run function doesn't appear to be working
- python - Merge dataframes Python without duplications
- javascript - JavaScript 数据结构中如何访问节点值
- c - 算法的递归关系
- rest - 转义包含参数名称的查询参数的值
- traefik - Traefik - 如何记录 request_body
- javascript - Writable computed variables does not read value when copying same value twice