Readlebee/server/sequelize/associations/User.js

40 lines
717 B
JavaScript
Raw Normal View History

module.exports = models => {
const {
User,
PermissionLevel,
Shelf,
Status,
Review,
Recommendation,
Follow,
} = models;
User.belongsTo(PermissionLevel, {
foreignKey: 'permissionLevel',
onDelete: 'SET NULL',
});
2020-01-25 21:52:37 +01:00
User.hasMany(Shelf, {
foreignKey: 'userId',
});
User.hasMany(Status, {
foreignKey: 'userId',
});
User.hasMany(Review, {
foreignKey: 'userId',
});
User.hasMany(Recommendation, {
foreignKey: 'toUser',
});
2020-01-25 21:52:37 +01:00
User.belongsToMany(User, {
through: Follow,
foreignKey: 'following',
2020-01-25 21:52:37 +01:00
as: 'following',
});
User.belongsToMany(User, {
through: Follow,
foreignKey: 'follower',
as: 'follower',
});
return User;
}