diff --git a/4-natours/after-section-11/models/reviewModel.js b/4-natours/after-section-11/models/reviewModel.js index 9e3c93031d..d0d167a3b1 100644 --- a/4-natours/after-section-11/models/reviewModel.js +++ b/4-natours/after-section-11/models/reviewModel.js @@ -87,15 +87,8 @@ reviewSchema.post('save', function() { // findByIdAndUpdate // findByIdAndDelete -reviewSchema.pre(/^findOneAnd/, async function(next) { - this.r = await this.findOne(); - // console.log(this.r); - next(); -}); - -reviewSchema.post(/^findOneAnd/, async function() { - // await this.findOne(); does NOT work here, query has already executed - await this.r.constructor.calcAverageRatings(this.r.tour); +reviewSchema.post(/^findOneAnd/, async function (doc) { + await this.model.calcAverageRatings(doc.tour); }); const Review = mongoose.model('Review', reviewSchema);