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); | ||||||
|  | 
 | ||||||
|  |     if (tcoll) { | ||||||
|       const foreignKey = this.options.foreignKey; |       const foreignKey = this.options.foreignKey; | ||||||
|  | 
 | ||||||
|       const field = tcoll.findField((field) => { |       const field = tcoll.findField((field) => { | ||||||
|         if (field.name === foreignKey) { |         if (field.name === foreignKey) { | ||||||
|           return true; |           return true; | ||||||
|         } |         } | ||||||
|         return field.type === 'belongsTo' && field.foreignKey === foreignKey; |         return field.type === 'belongsTo' && field.foreignKey === foreignKey; | ||||||
|       }); |       }); | ||||||
|  | 
 | ||||||
|       if (!field) { |       if (!field) { | ||||||
|         tcoll.model.removeAttribute(foreignKey); |         tcoll.model.removeAttribute(foreignKey); | ||||||
|       } |       } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     const association = collection.model.associations[this.name]; |     const association = collection.model.associations[this.name]; | ||||||
|  | 
 | ||||||
|  |     if (association) { | ||||||
|       this.database.referenceMap.removeReference(this.reference(association)); |       this.database.referenceMap.removeReference(this.reference(association)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     this.clearAccessors(); |     this.clearAccessors(); | ||||||
|     // 删掉 model 的关联字段
 |     // 删掉 model 的关联字段
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user