Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Add associate() to sequelize models #149

Closed
wants to merge 1 commit into from

Conversation

Qard
Copy link
Contributor

@Qard Qard commented Sep 17, 2016

This adds a helpful associate() function to sequelize models which makes describing relational connections more straight forward.

const {models} = sequelize;
app.set('models', models);
Object.keys(models).forEach(name => {
if ('associate' in models[name]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is associate coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from classMethods.associate in generators/model/templates/sequelize.js. This change would include an empty associate function on sequelize models which get called after all the models are registered, that way the model load order doesn't matter.

I noticed after making this PR that this same design was already in discussion in #94. They did bring up the point though that the model.sync() bits would also need to be moved until after these associate functions run though.

@ekryski
Copy link
Member

ekryski commented Oct 16, 2016

Given that the generators are getting an overhaul right now and are likely to be done soon. Let's keep this open for reference but this won't get merged into this branch. Thanks for submitting the PR @Qard! 😄

@daffl
Copy link
Member

daffl commented Feb 8, 2017

This has been added in v1.0.0-pre.1 via #159

@daffl daffl closed this Feb 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants