Last active
April 4, 2019 21:45
-
-
Save Rowadz/c6bd2983fc0e8b82206a4c44b662da38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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