fix: association not found error

This commit is contained in:
chareice 2022-11-24 18:03:10 +08:00
parent 9aba8016fe
commit 78402c394b

View File

@ -84,18 +84,21 @@ export class BelongsToField extends RelationField {
const foreignKey = this.options.foreignKey; const foreignKey = this.options.foreignKey;
const field1 = collection.getField(foreignKey); const field1 = collection.getField(foreignKey);
const field2 = tcoll ? tcoll.findField((field) => { const field2 = tcoll
return field.type === 'hasMany' && field.foreignKey === foreignKey; ? tcoll.findField((field) => {
}) : null; return field.type === 'hasMany' && field.foreignKey === foreignKey;
})
: null;
if (!field1 && !field2) { if (!field1 && !field2) {
collection.model.removeAttribute(foreignKey); collection.model.removeAttribute(foreignKey);
} }
const association = collection.model.associations[this.name]; const association = collection.model.associations[this.name];
const reference = this.reference(association); if (association) {
const reference = this.reference(association);
this.database.referenceMap.removeReference(reference); this.database.referenceMap.removeReference(reference);
}
this.clearAccessors(); this.clearAccessors();
// 删掉 model 的关联字段 // 删掉 model 的关联字段