Add extra scopes and associations for Review and BookReference
This commit is contained in:
parent
ccf55e1955
commit
a3f6137dec
|
@ -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',
|
||||
});
|
||||
|
||||
|
|
|
@ -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 } },
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Reference in New Issue