fix: can not disassociate before destroy data
This commit is contained in:
parent
f9c4fb9df0
commit
365513909a
@ -453,7 +453,8 @@ export async function destroy(ctx: Context, next: Next) {
|
|||||||
const { where } = TargetModel.parseApiJson({ filter, context: ctx });
|
const { where } = TargetModel.parseApiJson({ filter, context: ctx });
|
||||||
if (resourceField instanceof HASONE || resourceField instanceof BELONGSTO) {
|
if (resourceField instanceof HASONE || resourceField instanceof BELONGSTO) {
|
||||||
const model: Model = await associated[getAccessor](commonOptions);
|
const model: Model = await associated[getAccessor](commonOptions);
|
||||||
await associated[setAccessor](null, commonOptions);
|
// TODO:不能程序上解除关系,直接通过 onDelete 触发,或者通过 afterDestroy 处理
|
||||||
|
// await associated[setAccessor](null, commonOptions);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
ctx.body = await model.destroy(commonOptions);
|
ctx.body = await model.destroy(commonOptions);
|
||||||
} else if (resourceField instanceof HASMANY || resourceField instanceof BELONGSTOMANY) {
|
} else if (resourceField instanceof HASMANY || resourceField instanceof BELONGSTOMANY) {
|
||||||
@ -462,7 +463,8 @@ export async function destroy(ctx: Context, next: Next) {
|
|||||||
where: resourceKey ? { [primaryKey]: resourceKey } : where,
|
where: resourceKey ? { [primaryKey]: resourceKey } : where,
|
||||||
...commonOptions
|
...commonOptions
|
||||||
});
|
});
|
||||||
await associated[removeAccessor](models, commonOptions);
|
// TODO:不能程序上解除关系,直接通过 onDelete 触发,或者通过 afterDestroy 处理
|
||||||
|
// await associated[removeAccessor](models, commonOptions);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
ctx.body = await TargetModel.destroy({
|
ctx.body = await TargetModel.destroy({
|
||||||
where: { [primaryKey]: { [Op.in]: models.map(item => item[primaryKey]) } },
|
where: { [primaryKey]: { [Op.in]: models.map(item => item[primaryKey]) } },
|
||||||
|
Loading…
Reference in New Issue
Block a user