Skip to content

Instantly share code, notes, and snippets.

@Rowadz
Last active April 4, 2019 21:45
Show Gist options
  • Save Rowadz/c6bd2983fc0e8b82206a4c44b662da38 to your computer and use it in GitHub Desktop.
Save Rowadz/c6bd2983fc0e8b82206a4c44b662da38 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 comments = sequelizeClient.define('comments', {
text: {
type: DataTypes.STRING,
allowNull: false
}
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
comments.associate = function (models) {
const { posts, users } = models;
comments.belongsTo(posts);
comments.belongsTo(users);
};
return comments;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment