Created
April 4, 2019 21:42
-
-
Save Rowadz/048720d2b2e77c76b4ac28691f80dd1c 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 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