From a3f6137dec79e611ed7f02a324a1db82477083c6 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 6 Feb 2020 17:27:45 -0700 Subject: [PATCH] Add extra scopes and associations for Review and BookReference --- server/sequelize/associations/BookReference.js | 11 +++++++++++ server/sequelize/models/Review.js | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/server/sequelize/associations/BookReference.js b/server/sequelize/associations/BookReference.js index 79739b1..c1f2c83 100644 --- a/server/sequelize/associations/BookReference.js +++ b/server/sequelize/associations/BookReference.js @@ -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', }); diff --git a/server/sequelize/models/Review.js b/server/sequelize/models/Review.js index bbbe870..a81728b 100644 --- a/server/sequelize/models/Review.js +++ b/server/sequelize/models/Review.js @@ -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 } }, + }, + }, }); \ No newline at end of file