Readlebee/server/sequelize/associations/User.js

32 lines
587 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',
});
User.hasMany(Shelf);
User.hasMany(Status);
User.hasMany(Review);
User.hasMany(Recommendation, {
foreignKey: 'toUser',
});
User.hasMany(Follow, {
foreignKey: 'follower',
as: 'Followers',
});
User.belongsTo(Follow.scope('internal'), {
foreignKey: 'following',
as: 'Follows',
});
return User;
}