forked from mirror/gorm
Fix tests for Scanner
This commit is contained in:
parent
6271cf0e55
commit
c6b1669c6a
|
@ -9,8 +9,8 @@ type BasePost struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HNPost struct {
|
type HNPost struct {
|
||||||
BasePost `gorm:"embedded"`
|
BasePost
|
||||||
Upvotes int32
|
Upvotes int32
|
||||||
}
|
}
|
||||||
|
|
||||||
type EngadgetPost struct {
|
type EngadgetPost struct {
|
||||||
|
|
7
scope.go
7
scope.go
|
@ -338,16 +338,15 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField) []*Field {
|
||||||
field.IsNormal = true
|
field.IsNormal = true
|
||||||
}
|
}
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
embedded := settings["EMBEDDED"]
|
if field.IsTime() || field.IsScanner() {
|
||||||
if embedded != "" {
|
field.IsNormal = true
|
||||||
|
} else if embedded := settings["EMBEDDED"]; strings.ToUpper(embedded) == "EMBEDDED" || (embedded == "" && fieldStruct.Anonymous) {
|
||||||
var fields []*Field
|
var fields []*Field
|
||||||
for _, field := range scope.New(field.Field.Addr().Interface()).Fields() {
|
for _, field := range scope.New(field.Field.Addr().Interface()).Fields() {
|
||||||
field.DBName = field.DBName
|
field.DBName = field.DBName
|
||||||
fields = append(fields, field)
|
fields = append(fields, field)
|
||||||
}
|
}
|
||||||
return fields
|
return fields
|
||||||
} else if field.IsTime() || field.IsScanner() {
|
|
||||||
field.IsNormal = true
|
|
||||||
} else {
|
} else {
|
||||||
if foreignKey == "" && scope.HasColumn(field.Name+"Id") {
|
if foreignKey == "" && scope.HasColumn(field.Name+"Id") {
|
||||||
field.Relationship = &relationship{ForeignKey: field.Name + "Id", Kind: "belongs_to"}
|
field.Relationship = &relationship{ForeignKey: field.Name + "Id", Kind: "belongs_to"}
|
||||||
|
|
|
@ -26,7 +26,7 @@ type User struct {
|
||||||
Latitude float64
|
Latitude float64
|
||||||
Languages []Language `gorm:"many2many:user_languages;"`
|
Languages []Language `gorm:"many2many:user_languages;"`
|
||||||
CompanyId int64
|
CompanyId int64
|
||||||
Company
|
Company Company
|
||||||
Role
|
Role
|
||||||
PasswordHash []byte
|
PasswordHash []byte
|
||||||
IgnoreMe int64 `sql:"-"`
|
IgnoreMe int64 `sql:"-"`
|
||||||
|
|
Loading…
Reference in New Issue