unrelate() 似乎没有更改或删除连接 table
unrelate() doesn't seem to be changing or deleting the join table
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'
}
},
我在数据库中看到连接 table usertaganswer_answeredoptions
中有一行包含所有预期信息。但我现在想删除该行。我试试这个:
theAnswer = await UserTagAnswer.query()
.where(inputs.userType + "Id", inputs.answeringUserId)
.where('tagId', answerObject.tag)
.eager('tag');
theAnswer[0].$relatedQuery('answer')
.unrelate();
我试图删除 'answer' 字段中的所有关系,但数据库中似乎没有任何变化。
我忘记了 unrelate()
调用中的 await
关键字。最终工作代码是:
await theAnswer[0].$relatedQuery('answer')
.unrelate();
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'
}
},
我在数据库中看到连接 table usertaganswer_answeredoptions
中有一行包含所有预期信息。但我现在想删除该行。我试试这个:
theAnswer = await UserTagAnswer.query()
.where(inputs.userType + "Id", inputs.answeringUserId)
.where('tagId', answerObject.tag)
.eager('tag');
theAnswer[0].$relatedQuery('answer')
.unrelate();
我试图删除 'answer' 字段中的所有关系,但数据库中似乎没有任何变化。
我忘记了 unrelate()
调用中的 await
关键字。最终工作代码是:
await theAnswer[0].$relatedQuery('answer')
.unrelate();