Fix query related resources with customized column name
This commit is contained in:
		
							parent
							
								
									03966a1e20
								
							
						
					
					
						commit
						a952601f21
					
				@ -395,8 +395,17 @@ func (scope *Scope) related(value interface{}, foreignKeys ...string) *Scope {
 | 
				
			|||||||
	fromFields := scope.Fields()
 | 
						fromFields := scope.Fields()
 | 
				
			||||||
	toFields := toScope.Fields()
 | 
						toFields := toScope.Fields()
 | 
				
			||||||
	for _, foreignKey := range append(foreignKeys, toScope.typeName()+"Id", scope.typeName()+"Id") {
 | 
						for _, foreignKey := range append(foreignKeys, toScope.typeName()+"Id", scope.typeName()+"Id") {
 | 
				
			||||||
		fromField := fromFields[ToDBName(foreignKey)]
 | 
							var fromField, toField *Field
 | 
				
			||||||
		toField := toFields[ToDBName(foreignKey)]
 | 
							if field, ok := scope.FieldByName(foreignKey); ok {
 | 
				
			||||||
 | 
								fromField = field
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								fromField = fromFields[ToDBName(foreignKey)]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if field, ok := toScope.FieldByName(foreignKey); ok {
 | 
				
			||||||
 | 
								toField = field
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								toField = toFields[ToDBName(foreignKey)]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if fromField != nil {
 | 
							if fromField != nil {
 | 
				
			||||||
			if relationship := fromField.Relationship; relationship != nil {
 | 
								if relationship := fromField.Relationship; relationship != nil {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user