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

I am curious to know that why and when we should use autoLoadEntities in nestjs Typeorm.



Solution 1:[1]

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

So, obviously, when you're wanting to use webpack or a monorepo.

Also, it's just nice when you don't want to worry about the glob in the first place. Of course, it won't be effective when it comes to the TypeORM CLI, but it's nice for your server code.

The why is because webpack doesn't keep all of your files, but makes a single file to be ran, so the glob pattern can no longer reference all of the entity files, as there are no separate files to reference

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jay McDoniel