nodejh / sequelize-automate

Automatically generate bare sequelize models from your database.
MIT License
116 stars 22 forks source link

Is there a way to generate relations(associations) as well? #29

Closed aekst closed 4 years ago

aekst commented 4 years ago

Can I generate associations like "HasOne/ BelongsTo" too? It seems that there are only "options" generated for foreign keys for model definition. So compound queries still need to be done manually.

nodejh commented 4 years ago

Not yet, and there are only "options" generated for foreign keys. 😅

aekst commented 4 years ago

Sorry for my ambiguity. What I wanna say is that I didn't find a proper way to utilize those indexes. I've skimmed through

https://sequelize.org/v5/class/lib/model.js~Model.html#static-method-init https://sequelize.org/v5/manual/models-definition.html#indexes https://sequelize.org/v5/class/lib/query-interface.js~QueryInterface.html#instance-method-addIndex https://sequelize.org/v5/manual/models-usage.html#eager-loading

but got no answer.

Are they sufficient to be used in a relation way?

nodejh commented 4 years ago

I think what you mean is Association, and I'm sorry to tell that the answer is No.

sequelize-automate can't create associations between models. The indexes are only descriptions of tables.

You could create association based on those models generated by sequelize-automate if you want to use it.