From c6b1669c6af213ca8cc573bce69f59351ef78bfb Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 30 Aug 2014 23:08:58 +0800 Subject: [PATCH] Fix tests for Scanner --- anonymous_struct_test.go | 4 ++-- scope.go | 7 +++---- structs_test.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/anonymous_struct_test.go b/anonymous_struct_test.go index 964732b4..fe571869 100644 --- a/anonymous_struct_test.go +++ b/anonymous_struct_test.go @@ -9,8 +9,8 @@ type BasePost struct { } type HNPost struct { - BasePost `gorm:"embedded"` - Upvotes int32 + BasePost + Upvotes int32 } type EngadgetPost struct { diff --git a/scope.go b/scope.go index bd853ca2..3420c6fb 100644 --- a/scope.go +++ b/scope.go @@ -338,16 +338,15 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField) []*Field { field.IsNormal = true } case reflect.Struct: - embedded := settings["EMBEDDED"] - if embedded != "" { + if field.IsTime() || field.IsScanner() { + field.IsNormal = true + } else if embedded := settings["EMBEDDED"]; strings.ToUpper(embedded) == "EMBEDDED" || (embedded == "" && fieldStruct.Anonymous) { var fields []*Field for _, field := range scope.New(field.Field.Addr().Interface()).Fields() { field.DBName = field.DBName fields = append(fields, field) } return fields - } else if field.IsTime() || field.IsScanner() { - field.IsNormal = true } else { if foreignKey == "" && scope.HasColumn(field.Name+"Id") { field.Relationship = &relationship{ForeignKey: field.Name + "Id", Kind: "belongs_to"} diff --git a/structs_test.go b/structs_test.go index dd2695ef..5ddc3b50 100644 --- a/structs_test.go +++ b/structs_test.go @@ -26,7 +26,7 @@ type User struct { Latitude float64 Languages []Language `gorm:"many2many:user_languages;"` CompanyId int64 - Company + Company Company Role PasswordHash []byte IgnoreMe int64 `sql:"-"`