improve some functions

This commit is contained in:
Lunny Xiao 2017-09-12 21:43:43 +08:00
parent 23c6999de8
commit 1d5bc623f3
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 6 additions and 0 deletions

View File

@ -886,8 +886,10 @@ func (session *Session) getByPK(pk core.PK, fieldValue *reflect.Value) error {
if has {
if fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil() {
fieldValue.Set(structInter)
fmt.Println("getByPK value ptr:", fieldValue.Interface())
} else if fieldValue.Kind() == reflect.Struct {
fieldValue.Set(structInter.Elem())
fmt.Println("getByPK value:", fieldValue.Interface())
} else {
return errors.New("set value failed")
}

View File

@ -5,6 +5,7 @@
package xorm
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
@ -164,6 +165,7 @@ func TestBelongsTo_Find(t *testing.T) {
err = testEngine.Cascade().Find(&noses2)
assert.NoError(t, err)
assert.Equal(t, 2, len(noses2))
fmt.Println("noses:", noses2)
assert.Equal(t, face1.Id, noses2[0].Face.Id)
assert.Equal(t, face2.Id, noses2[1].Face.Id)
assert.Equal(t, "face1", noses2[0].Face.Name)

View File

@ -203,7 +203,9 @@ func (session *Session) noCacheFind(table *core.Table, containerValue reflect.Va
if isPointer {
containerValue.Set(reflect.Append(containerValue, newValue.Elem().Addr()))
} else {
fmt.Println("---", newValue.Elem())
containerValue.Set(reflect.Append(containerValue, newValue.Elem()))
fmt.Println("===", containerValue.Interface())
}
return nil
}