Please provide an example using sequelize v5 and TypeScript.
mrdulin opened this issue · 6 comments
In particular, how to organize the models when using sequelize v5 and TypeScript?
I wonder can we remove this setup file: https://github.com/sequelize/express-example/blob/master/models/index.js and organize the models file just using export
and import
, and combine these models using some method.
The setup file executes immediately when importing it, or import some modules depend on it. Sometimes, It will affect the unit test when importing some modules into test files.
E.g.
models/index.ts
:
import {User} from './user';
import {Role} from './Role';
import {Project} from './Project';
const models = combineModels([User, Role, Project])
// ...
export {models};
I wonder can we remove this setup file: https://github.com/sequelize/express-example/blob/master/models/index.js and organize the models file just using
export
andimport
, and combine these models using some method.
Yes, definitely, this is something I want to do in the near future.
@papb I made a example using sequelize v5 and TypeScript. But I met an issue, it blocks me one week. Can you help me solve this issue? I also submitted a post on stackoverflow, but it still has no working answer.
I am thinking if the organization of models is correct or not.
Here is the post on SO: https://stackoverflow.com/questions/60054969/belongs-to-many-associations-add-foreign-keys-to-source-model-sequelizedatabase
Here is the example repo: https://github.com/mrdulin/node-sequelize-examples/tree/master/src/db
Thanks!
I figured it out.
Hi @mrdulin sorry I couldn't give you more attention, I have too little time hehe. Glad you figured it out. Can you please share it? Or update your github repository? When I have time I would like to take a look and incorporate it as an example for this repository, of course giving all credits to you. Thank you very much.