我正在嘗試根據架構中其他兩個欄位的值設定一個值,但我收到以下錯誤
ReferenceError:在初始化之前無法訪問“isPending”
這是模型
const mongoose = require('mongoose');
const bookingSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User',
},
sitterId: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'Sitter',
},
start: {
type: Date,
required: true,
},
end: {
type: Date,
required: true,
min: this.start,
},
accepted: {
type: Boolean,
default: false,
},
declined: {
type: Boolean,
default: false,
},
paid: {
type: Boolean,
default: false,
},
pending: {
type: Boolean,
default: true,
set: isPending,
},
});
const isPending = (accepted, declined) => {
!accepted && !declined ? true : false;
};
有任何想法嗎?有可能嗎
uj5u.com熱心網友回復:
檢查這個
用于this訪問其他欄位值:
pending: {
type: Boolean,
default: true,
set: function() { return !this.accepted && !this.declined }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/429520.html
上一篇:如何使用Mongoose在MongoDB中創建互連模式?
下一篇:如何使貓鼬區分大小寫?
