From 6c1ca7adb82ef5981165037d8834c9b94e0eb2ba Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 14 Oct 2014 00:06:41 +0800 Subject: [PATCH] Include ignored columns in Fields(), it could be used as cache field --- scope.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scope.go b/scope.go index 242f473a..15413e1b 100644 --- a/scope.go +++ b/scope.go @@ -414,11 +414,12 @@ func (scope *Scope) Fields(noRelations ...bool) map[string]*Field { if field.IsPrimaryKey { hasPrimaryKey = true } - if field.IsIgnored { - continue - } - if _, ok := fields[field.DBName]; ok { - panic(fmt.Sprintf("Duplicated column name for %v (%v)\n", scope.typeName(), fileWithLineNum())) + if value, ok := fields[field.DBName]; ok { + if value.IsIgnored { + fields[field.DBName] = field + } else if !value.IsIgnored { + panic(fmt.Sprintf("Duplicated column name for %v (%v)\n", scope.typeName(), fileWithLineNum())) + } } else { fields[field.DBName] = field }