Created
November 28, 2018 10:50
-
-
Save Eth3rnit3/615efd2a7eba278392d4242e562fd972 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
'use strict'; | |
module.exports = (sequelize, DataTypes) => { | |
const User = sequelize.define('User', { | |
email: DataTypes.STRING, | |
firstName: DataTypes.STRING, | |
lastName: DataTypes.STRING, | |
companyId: DataTypes.INTEGER | |
}, {}); | |
User.associate = function(models) { | |
User.belongsTo(models.Company, {foreignKey: 'companyId', as: 'company'}) | |
User.belongsToMany(models.WorkingDay, {through: 'UsersWorkingDays', foreignKey: 'userId', as: 'days'}) | |
}; | |
return User; | |
}; |
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
'use strict'; | |
module.exports = (sequelize, DataTypes) => { | |
const UsersWorkingDay = sequelize.define('UsersWorkingDay', { | |
userId: DataTypes.INTEGER, | |
workingDayId: DataTypes.INTEGER | |
}, {}); | |
UsersWorkingDay.associate = function(models) { | |
UsersWorkingDay.belongsTo(models.User, {foreignKey: 'userId'}) | |
UsersWorkingDay.belongsTo(models.WorkingDay, {foreignKey: 'workingDayId'}) | |
}; | |
return UsersWorkingDay; | |
}; |
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
'use strict'; | |
module.exports = (sequelize, DataTypes) => { | |
const WorkingDay = sequelize.define('WorkingDay', { | |
weekDay: DataTypes.STRING, | |
workingDate: DataTypes.DATE, | |
isWorking: DataTypes.BOOLEAN | |
}, {}); | |
WorkingDay.associate = function(models) { | |
WorkingDay.belongsToMany(models.User, {through: 'UsersWorkingDays', foreignKey: 'workingDayId', as: 'employes'}) | |
}; | |
return WorkingDay; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment