Include ignored columns in Fields(), it could be used as cache field

This commit is contained in:
Jinzhu 2014-10-14 00:06:41 +08:00
parent 5d0d2a8e98
commit 6c1ca7adb8
1 changed files with 6 additions and 5 deletions

View File

@ -414,11 +414,12 @@ func (scope *Scope) Fields(noRelations ...bool) map[string]*Field {
if field.IsPrimaryKey { if field.IsPrimaryKey {
hasPrimaryKey = true hasPrimaryKey = true
} }
if field.IsIgnored { if value, ok := fields[field.DBName]; ok {
continue if value.IsIgnored {
} fields[field.DBName] = field
if _, ok := fields[field.DBName]; ok { } else if !value.IsIgnored {
panic(fmt.Sprintf("Duplicated column name for %v (%v)\n", scope.typeName(), fileWithLineNum())) panic(fmt.Sprintf("Duplicated column name for %v (%v)\n", scope.typeName(), fileWithLineNum()))
}
} else { } else {
fields[field.DBName] = field fields[field.DBName] = field
} }