fix: unbind error (#1094)
This commit is contained in:
parent
ff267456de
commit
f8f9b8cc9f
@ -154,19 +154,27 @@ export class HasOneField extends RelationField {
|
|||||||
database.removePendingField(this);
|
database.removePendingField(this);
|
||||||
// 如果关系表内没有显式的创建外键字段,删除关系时,外键也删除掉
|
// 如果关系表内没有显式的创建外键字段,删除关系时,外键也删除掉
|
||||||
const tcoll = database.collections.get(this.target);
|
const tcoll = database.collections.get(this.target);
|
||||||
const foreignKey = this.options.foreignKey;
|
|
||||||
const field = tcoll.findField((field) => {
|
if (tcoll) {
|
||||||
if (field.name === foreignKey) {
|
const foreignKey = this.options.foreignKey;
|
||||||
return true;
|
|
||||||
|
const field = tcoll.findField((field) => {
|
||||||
|
if (field.name === foreignKey) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return field.type === 'belongsTo' && field.foreignKey === foreignKey;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!field) {
|
||||||
|
tcoll.model.removeAttribute(foreignKey);
|
||||||
}
|
}
|
||||||
return field.type === 'belongsTo' && field.foreignKey === foreignKey;
|
|
||||||
});
|
|
||||||
if (!field) {
|
|
||||||
tcoll.model.removeAttribute(foreignKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const association = collection.model.associations[this.name];
|
const association = collection.model.associations[this.name];
|
||||||
this.database.referenceMap.removeReference(this.reference(association));
|
|
||||||
|
if (association) {
|
||||||
|
this.database.referenceMap.removeReference(this.reference(association));
|
||||||
|
}
|
||||||
|
|
||||||
this.clearAccessors();
|
this.clearAccessors();
|
||||||
// 删掉 model 的关联字段
|
// 删掉 model 的关联字段
|
||||||
|
Loading…
Reference in New Issue
Block a user