From 79225bfe48831236b060a019e15b473e20644b64 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 18 Feb 2021 10:53:29 +0800 Subject: [PATCH] Fix Omit/Select without Model value, close #4098 --- statement.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/statement.go b/statement.go index aac4f073..0cb2ca32 100644 --- a/statement.go +++ b/statement.go @@ -600,12 +600,14 @@ func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) ( // select columns for _, column := range stmt.Selects { - if column == "*" { + if stmt.Schema == nil { + results[column] = true + } else if column == "*" { notRestricted = true for _, dbName := range stmt.Schema.DBNames { results[dbName] = true } - } else if column == clause.Associations && stmt.Schema != nil { + } else if column == clause.Associations { for _, rel := range stmt.Schema.Relationships.Relations { results[rel.Name] = true } @@ -618,11 +620,11 @@ func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) ( // omit columns for _, omit := range stmt.Omits { - if omit == clause.Associations { - if stmt.Schema != nil { - for _, rel := range stmt.Schema.Relationships.Relations { - results[rel.Name] = false - } + if stmt.Schema == nil { + results[omit] = false + } else if omit == clause.Associations { + for _, rel := range stmt.Schema.Relationships.Relations { + results[rel.Name] = false } } else if field := stmt.Schema.LookUpField(omit); field != nil && field.DBName != "" { results[field.DBName] = false