From e77156980cd74639fefdaf0576785018464a3ca1 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 17 Jul 2020 15:49:41 +0800 Subject: [PATCH] Fix panic when using Select/Omit Associations with no schema, close #3160 --- statement.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/statement.go b/statement.go index 38154939..3a2344ae 100644 --- a/statement.go +++ b/statement.go @@ -503,7 +503,7 @@ func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) ( for _, dbName := range stmt.Schema.DBNames { results[dbName] = true } - } else if column == clause.Associations { + } else if column == clause.Associations && stmt.Schema != nil { for _, rel := range stmt.Schema.Relationships.Relations { results[rel.Name] = true } @@ -517,8 +517,10 @@ func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) ( // omit columns for _, omit := range stmt.Omits { if omit == clause.Associations { - for _, rel := range stmt.Schema.Relationships.Relations { - results[rel.Name] = false + if stmt.Schema != nil { + 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