Add extra scopes and associations for Review and BookReference

This commit is contained in:
Robbie Antenesse 2020-02-06 17:27:45 -07:00
parent ccf55e1955
commit a3f6137dec
2 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,17 @@ module.exports = models => {
} = models;
BookReference.hasMany(Review, {
as: 'Interactions',
foreignKey: 'bookReferenceId',
});
BookReference.hasMany(Review.scope('Text'), {
as: 'Reviews',
foreignKey: 'bookReferenceId',
});
BookReference.hasMany(Review.scope('Rating'), {
as: 'Ratings',
foreignKey: 'bookReferenceId',
});

View File

@ -67,4 +67,12 @@ module.exports = sequelize => sequelize.define('Review', {
fields: ['bookReferenceId'],
},
],
scopes: {
Rating: {
where: { rating: { [Sequelize.Op.not]: null } },
},
Text: {
where: { text: { [Sequelize.Op.not]: null } },
},
},
});