w3tecch / express-typescript-boilerplate

A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch
MIT License
3.31k stars 905 forks source link

[question] Using sub directories of models with typeorm and .env config #93

Closed mwiley63 closed 6 years ago

mwiley63 commented 6 years ago

Hello,

What would be the recommended way to add sub directories to the models folder? When I do the following I get an error with typeorm (as the generated ormconfig.json does not include all the sub directories by default):

  models/
     User.ts
     user-details/
        UserRole.ts

If I include a type from UserRole.ts into User.ts, I get an error, "Entity Metadata not found". After looking at the ormconfig.json, I can see that the user-details sub directory is not included into the entities array.

As a hack I hard-coded each entity directory into the ormconfgi.ts command file. Is there a better way to do this?

Thank you!

dweber019 commented 6 years ago

Hi @mwiley63

Does it work if you change entities in env.ts to api/models/**/*{.js,.ts}?

Cheers

mwiley63 commented 6 years ago

Hi @dweber019

That worked! Can't believe I missed the env.ts file 👍

Thanks!

dweber019 commented 6 years ago

I'll change this to be more open in the future.

dweber019 commented 6 years ago

https://github.com/w3tecch/express-typescript-boilerplate/pull/94 fixes this.