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