forked from mirror/gorm
Merge pull request #284 from shirou/master
fix panic problem when the struct has unexported field.
This commit is contained in:
commit
84954e6779
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go/ast"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -550,6 +551,9 @@ func (scope *Scope) createTable() *Scope {
|
||||||
fields := scope.Fields()
|
fields := scope.Fields()
|
||||||
scopeType := scope.IndirectValue().Type()
|
scopeType := scope.IndirectValue().Type()
|
||||||
for i := 0; i < scopeType.NumField(); i++ {
|
for i := 0; i < scopeType.NumField(); i++ {
|
||||||
|
if !ast.IsExported(scopeType.Field(i).Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, field := range scope.fieldFromStruct(scopeType.Field(i), false) {
|
for _, field := range scope.fieldFromStruct(scopeType.Field(i), false) {
|
||||||
field = fields[field.DBName]
|
field = fields[field.DBName]
|
||||||
if field.IsNormal {
|
if field.IsNormal {
|
||||||
|
|
|
@ -125,12 +125,13 @@ func (i *Num) Scan(src interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Animal struct {
|
type Animal struct {
|
||||||
Counter uint64 `gorm:"primary_key:yes"`
|
Counter uint64 `gorm:"primary_key:yes"`
|
||||||
Name string `sql:"DEFAULT:'galeone'"`
|
Name string `sql:"DEFAULT:'galeone'"`
|
||||||
From string //test reserved sql keyword as field name
|
From string //test reserved sql keyword as field name
|
||||||
Age time.Time `sql:"DEFAULT:current_timestamp"`
|
Age time.Time `sql:"DEFAULT:current_timestamp"`
|
||||||
CreatedAt time.Time
|
unexported string // unexported value
|
||||||
UpdatedAt time.Time
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
|
|
Loading…
Reference in New Issue