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

Model association for sequalize-cli 4.0.0 updates #620

Merged
merged 4 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/assets/models/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ module.exports = (sequelize, DataTypes) => {
<% }) %>
}, {
<%= underscored ? 'underscored: true,' : '' %>
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});

<%= name %>.associate = function(models) {
// associations can be defined here
};

return <%= name %>;
};
3 changes: 2 additions & 1 deletion test/model/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const _ = require('lodash');

const targetContent = attrUnd.underscored ?
'underscored: true'
: '{\n classMethods';
: '{});';
Copy link
Contributor

Choose a reason for hiding this comment

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

assert associate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for being a bit dense. I am not sure what you are wanting.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to check if generated model contain associate method, just scanning file with .associate around here should be enough

Just add .pipe(helpers.ensureContent('.associate'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. Will do.


if ( attrUnd.underscored ) {
flags.underscored = attrUnd.underscored;
Expand All @@ -210,6 +210,7 @@ const _ = require('lodash');
.src(Support.resolveSupportPath('tmp', 'models'))
.pipe(helpers.readFile('user.js'))
.pipe(helpers.ensureContent(targetContent))
.pipe(helpers.ensureContent('.associate'))
.pipe(helpers.teardown(done));
});
});
Expand Down