Skip to content

Instantly share code, notes, and snippets.

@Rowadz
Created April 4, 2019 21:42
Show Gist options
  • Select an option

  • Save Rowadz/048720d2b2e77c76b4ac28691f80dd1c to your computer and use it in GitHub Desktop.

Select an option

Save Rowadz/048720d2b2e77c76b4ac28691f80dd1c to your computer and use it in GitHub Desktop.
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const users = sequelizeClient.define('users', {
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
password: {
type: DataTypes.STRING,
allowNull: false
},
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
users.associate = function (models) {
const { comments, posts } = models;
users.hasMany(comments); // Will add userId to comments model
users.hasMany(posts); // Will add userId to posts model
};
return users;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment