Don't check relations if field is ignored

This commit is contained in:
Jinzhu 2014-08-14 21:45:42 +08:00
parent 131b504941
commit febc826511
3 changed files with 50 additions and 46 deletions

View File

@ -265,6 +265,7 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField) *Field {
field.Tag = fieldStruct.Tag
field.SqlTag = scope.sqlTagForField(&field)
if !field.IsIgnored {
// parse association
typ := indirectValue.Type()
foreignKey := SnakeToUpperCamel(settings["FOREIGNKEY"])
@ -318,6 +319,7 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField) *Field {
}
}
}
}
return &field
}

View File

@ -308,6 +308,7 @@ func (scope *Scope) sqlTagForField(field *Field) (typ string) {
fieldTag := field.Tag.Get(scope.db.parent.tagIdentifier)
if fieldTag == "-" {
field.IsIgnored = true
return
}
var setting = parseTagSetting(fieldTag)

View File

@ -86,6 +86,7 @@ type Product struct {
type Company struct {
Id int64
Name string
Owner *User `sql:"-"`
}
type Role struct {