forked from mirror/gorm
Fix scanIntoStruct (#5241)
* Reproduces error case * Fix scanIntoStruct Co-authored-by: Filippo Del Moro <filippo.delmoro@facile.it>
This commit is contained in:
parent
74e07b049c
commit
6aa6d37fc4
2
scan.go
2
scan.go
|
@ -74,7 +74,7 @@ func (db *DB) scanIntoStruct(rows Rows, reflectValue reflect.Value, values []int
|
|||
relValue := joinFields[idx][0].ReflectValueOf(db.Statement.Context, reflectValue)
|
||||
if relValue.Kind() == reflect.Ptr && relValue.IsNil() {
|
||||
if value := reflect.ValueOf(values[idx]).Elem(); value.Kind() == reflect.Ptr && value.IsNil() {
|
||||
return
|
||||
continue
|
||||
}
|
||||
|
||||
relValue.Set(reflect.New(relValue.Type().Elem()))
|
||||
|
|
|
@ -10,12 +10,12 @@ import (
|
|||
)
|
||||
|
||||
func TestJoins(t *testing.T) {
|
||||
user := *GetUser("joins-1", Config{Company: true, Manager: true, Account: true})
|
||||
user := *GetUser("joins-1", Config{Company: true, Manager: true, Account: true, NamedPet: false})
|
||||
|
||||
DB.Create(&user)
|
||||
|
||||
var user2 User
|
||||
if err := DB.Joins("Company").Joins("Manager").Joins("Account").First(&user2, "users.name = ?", user.Name).Error; err != nil {
|
||||
if err := DB.Joins("NamedPet").Joins("Company").Joins("Manager").Joins("Account").First(&user2, "users.name = ?", user.Name).Error; err != nil {
|
||||
t.Fatalf("Failed to load with joins, got error: %v", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue