2020-01-14 23:26:39 +01:00
|
|
|
module.exports = models => {
|
|
|
|
const {
|
|
|
|
Review,
|
|
|
|
User,
|
|
|
|
PermissionLevel,
|
|
|
|
BookReference,
|
2020-01-25 21:52:37 +01:00
|
|
|
Reaction,
|
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-25 21:52:37 +01:00
|
|
|
Review.hasMany(Reaction.scope('Review'), {
|
2020-01-15 22:01:14 +01:00
|
|
|
foreignKey: 'targetId',
|
|
|
|
constraints: false,
|
|
|
|
as: 'Reactions',
|
|
|
|
});
|
|
|
|
|
2020-01-14 23:26:39 +01:00
|
|
|
return Review;
|
|
|
|
}
|