UserTagAnswer模型:
answer: {
relation: Model.ManyToManyRelation,
modelClass: sails.config.models.UserTagAnswerOptions,
join: {
from: 'usertaganswer.id',
through: {
from: 'usertaganswer_answeredoptions.userTagAnswerId',
to: 'usertaganswer_answeredoptions.userTagAnswerOptionId'
},
to: 'usertagansweroptions.id'
}
},
UserTagAnswerOptions模型
userTagAnswers: {
relation: Model.ManyToManyRelation,
modelClass: sails.config.models.UserTagAnswer,
join: {
from: 'usertagansweroptions.id',
through: {
from: 'usertaganswer_answeredoptions.userTagAnswerOptionId',
to: 'usertaganswer_answeredoptions.userTagAnswerId'
},
to: 'usertaganswer.id'
}
},
我在数据库中看到联接表usertaganswer_answeredoptions
中有一行包含所有期望的信息。但我现在想删除该行。我尝试这样做:
theAnswer = await UserTagAnswer.query()
.where(inputs.userType + "Id", inputs.answeringUserId)
.where('tagId', answerObject.tag)
.eager('tag');
theAnswer[0].$relatedQuery('answer')
.unrelate();
我正在尝试删除“答案”字段中的所有关系,但是数据库中似乎没有任何更改。
答案 0 :(得分:0)
我在await
通话中忘记了unrelate()
关键字。最终的工作代码是:
await theAnswer[0].$relatedQuery('answer')
.unrelate();