2020-01-14 23:26:39 +01:00
|
|
|
module.exports = models => {
|
|
|
|
const {
|
|
|
|
Review,
|
|
|
|
User,
|
|
|
|
PermissionLevel,
|
|
|
|
BookReference,
|
2020-01-15 22:01:14 +01:00
|
|
|
Reactions,
|
2020-01-14 23:26:39 +01:00
|
|
|
} = models;
|
|
|
|
|
|
|
|
Review.belongsTo(User, {
|
|
|
|
foreignKey: 'userId',
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
});
|
|
|
|
|
|
|
|
Review.belongsTo(PermissionLevel, {
|
|
|
|
foreignKey: 'permissionLevel',
|
|
|
|
onDelete: 'SET NULL',
|
|
|
|
});
|
|
|
|
|
|
|
|
Review.belongsTo(BookReference, {
|
|
|
|
foreignKey: 'bookReferenceId',
|
|
|
|
onDelete: 'SET NULL',
|
|
|
|
});
|
|
|
|
|
2020-01-15 22:01:14 +01:00
|
|
|
Review.hasMany(Reactions.scope('Review'), {
|
|
|
|
foreignKey: 'targetId',
|
|
|
|
constraints: false,
|
|
|
|
as: 'Reactions',
|
|
|
|
});
|
|
|
|
|
2020-01-14 23:26:39 +01:00
|
|
|
return Review;
|
|
|
|
}
|