fix: association not found error
This commit is contained in:
		
							parent
							
								
									9aba8016fe
								
							
						
					
					
						commit
						78402c394b
					
				@ -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 的关联字段
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user