From 1b37300a53adaece3873dbaaf9c02e24ccc141b0 Mon Sep 17 00:00:00 2001 From: Illia Ovchynnikov Date: Mon, 17 Jun 2019 09:09:00 +0200 Subject: [PATCH] Support for readonly transient field #394 --- db.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db.go b/db.go index 30e16ca7..49c939f5 100644 --- a/db.go +++ b/db.go @@ -320,6 +320,7 @@ func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey var isAuto bool var isPK bool var isNotNull bool + var isReadOnly bool for _, argString := range cArguments[1:] { argString = strings.TrimSpace(argString) arg := strings.SplitN(argString, ":", 2) @@ -349,6 +350,8 @@ func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey isAuto = true case "notnull": isNotNull = true + case "readonly": + isReadOnly = true default: panic(fmt.Sprintf("Unrecognized tag option for field %v: %v", f.Name, arg)) } @@ -390,7 +393,7 @@ func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey cm := &ColumnMap{ ColumnName: columnName, DefaultValue: defaultValue, - Transient: columnName == "-", + Transient: columnName == "-" || isReadOnly, fieldName: f.Name, gotype: gotype, isPK: isPK,