Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide an example using sequelize v5 and TypeScript. #97

Closed
mrdulin opened this issue Jan 23, 2020 · 6 comments
Closed

Please provide an example using sequelize v5 and TypeScript. #97

mrdulin opened this issue Jan 23, 2020 · 6 comments

Comments

@mrdulin
Copy link

mrdulin commented Jan 23, 2020

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};
@papb
Copy link
Member

papb commented Jan 23, 2020

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.

Yes, definitely, this is something I want to do in the near future.

@mrdulin
Copy link
Author

mrdulin commented Feb 5, 2020

@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!

@mrdulin
Copy link
Author

mrdulin commented Feb 11, 2020

I figured it out.

@papb
Copy link
Member

papb commented Feb 11, 2020

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.

@mrdulin
Copy link
Author

mrdulin commented Feb 11, 2020

@papb I made a stupid mistake. I passed a wrong modelName(Category) to the Language model. I copied the code from the Category model file, forgot to changing the modelName. After fixing it, the integration tests passed. I already updated the examples in the repo.

@papb
Copy link
Member

papb commented Jul 19, 2020

Hi @mrdulin, we have another issue (#104) also requesting a TypeScript example, so I will close this one as a duplicate for now. The current JS example has been updated to use v6 and should work with v5 as well.

Hopefully I will add a TS example in the near future. Thank you again!

@papb papb closed this as completed Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants