mirror of https://github.com/go-gorm/gorm.git
Fix Preload with nil pointer
This commit is contained in:
parent
74e7a9ca07
commit
d483ffa45c
|
@ -110,7 +110,6 @@ func (p *processor) Execute(db *DB) {
|
|||
for stmt.ReflectValue.Kind() == reflect.Ptr {
|
||||
if stmt.ReflectValue.IsNil() && stmt.ReflectValue.CanAddr() {
|
||||
stmt.ReflectValue.Set(reflect.New(stmt.ReflectValue.Type().Elem()))
|
||||
break
|
||||
}
|
||||
|
||||
stmt.ReflectValue = stmt.ReflectValue.Elem()
|
||||
|
|
|
@ -27,7 +27,6 @@ func preload(db *gorm.DB, rel *schema.Relationship, conds []interface{}, preload
|
|||
})
|
||||
|
||||
if rel.JoinTable != nil {
|
||||
|
||||
var (
|
||||
joinForeignFields = make([]*schema.Field, 0, len(rel.References))
|
||||
joinRelForeignFields = make([]*schema.Field, 0, len(rel.References))
|
||||
|
|
|
@ -63,12 +63,15 @@ func TestNestedPreload(t *testing.T) {
|
|||
|
||||
var user2 User
|
||||
DB.Preload("Pets.Toy").Find(&user2, "id = ?", user.ID)
|
||||
|
||||
CheckUser(t, user2, user)
|
||||
|
||||
var user3 User
|
||||
DB.Preload(clause.Associations+"."+clause.Associations).Find(&user3, "id = ?", user.ID)
|
||||
CheckUser(t, user3, user)
|
||||
|
||||
var user4 *User
|
||||
DB.Preload("Pets.Toy").Find(&user4, "id = ?", user.ID)
|
||||
CheckUser(t, *user4, user)
|
||||
}
|
||||
|
||||
func TestNestedPreloadForSlice(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue