为什么以及何时我们应该在 nestjs Typeorm 中使用 `autoLoadEntities`

why and when we should use `autoLoadEntities` in nestjs Typeorm

我很想知道为什么以及什么时候我们应该在 nestjs Typeorm 中使用 autoLoadEntities

Note, however, that glob paths are not supported by webpack, so if you are building your application within a monorepo, you won't be able to use them. To address this issue, an alternative solution is provided. To automatically load entities, set the autoLoadEntities property of the configuration object (passed into the forRoot() method) to true, as shown below

From the docs

所以,很明显,当你想使用 webpack 或 monorepo 时。

此外,当您一开始就不想担心 glob 时,这很好。当然,当它涉及到 TypeORM CLI 时它不会有效,但它对您的服务器代码很好。

原因是因为 webpack 不会保留所有文件,而是将单个文件设为 运行,因此 glob 模式无法再引用所有 entity 文件,因为没有单独的文件可供参考