例如,我有两个模型; UserTags和UserTagAnswers
UserTag:
module.exports = {
attributes: {
id: {
type: 'number',
autoIncrement: true,
},
questionTitle: {
type: 'string',
required: true
},
factTitle: {
type: 'string',
required: true,
unique: true
},
options: {
type: 'json'
},
type: {
type: 'string',
required: true,
isIn: ['checkbox', 'number', 'dropdown'],
},
defaultValue: {
type: 'string',
}
},
};
UserTagAnswer:
module.exports = {
attributes: {
id: {
type: 'number',
autoIncrement: true,
},
user: {
model: 'User'
},
inactiveUser: {
model: 'InactiveUser'
},
tag: {
model: 'UserTag',
required: true
},
answer: {
type: 'json',
required: true
}
},
};
当我进行查询UserTagAnswer.find({inactiveUser: '1234', tag: '9876'})
时,我希望尝试进行普通查询,但是如果查询找到0个文档,则希望从对应的UserTag中返回defaultValue。即UserTag.find({id: '9876'}).select(['defaultValue'])
我不确定在Waterline中这是否可行,或者我设计的模型不正确,但这就是我要寻找的功能。