Fix invalid preload SQL when no data found, close #4443
This commit is contained in:
		
							parent
							
								
									c73fe96cfd
								
							
						
					
					
						commit
						b13732c450
					
				| @ -104,15 +104,17 @@ func preload(db *gorm.DB, rel *schema.Relationship, conds []interface{}, preload | |||||||
| 	reflectResults := rel.FieldSchema.MakeSlice().Elem() | 	reflectResults := rel.FieldSchema.MakeSlice().Elem() | ||||||
| 	column, values := schema.ToQueryValues(clause.CurrentTable, relForeignKeys, foreignValues) | 	column, values := schema.ToQueryValues(clause.CurrentTable, relForeignKeys, foreignValues) | ||||||
| 
 | 
 | ||||||
| 	for _, cond := range conds { | 	if len(values) != 0 { | ||||||
| 		if fc, ok := cond.(func(*gorm.DB) *gorm.DB); ok { | 		for _, cond := range conds { | ||||||
| 			tx = fc(tx) | 			if fc, ok := cond.(func(*gorm.DB) *gorm.DB); ok { | ||||||
| 		} else { | 				tx = fc(tx) | ||||||
| 			inlineConds = append(inlineConds, cond) | 			} else { | ||||||
|  | 				inlineConds = append(inlineConds, cond) | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	db.AddError(tx.Where(clause.IN{Column: column, Values: values}).Find(reflectResults.Addr().Interface(), inlineConds...).Error) | 		db.AddError(tx.Where(clause.IN{Column: column, Values: values}).Find(reflectResults.Addr().Interface(), inlineConds...).Error) | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	fieldValues := make([]interface{}, len(relForeignFields)) | 	fieldValues := make([]interface{}, len(relForeignFields)) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu