From 8316f94b72719208b2d939c70f3824287e62ea5d Mon Sep 17 00:00:00 2001 From: Brent Hughes Date: Wed, 2 Jan 2019 07:28:46 -0600 Subject: [PATCH] Fix Panic in test scenerio (#2131) I have found that there are times when testing that if I did not create the database through Open() it will not have the parent set and cause a panic when it hits this code path. --- model_struct.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model_struct.go b/model_struct.go index 08e741fe..9e93db63 100644 --- a/model_struct.go +++ b/model_struct.go @@ -40,7 +40,7 @@ func (s *ModelStruct) TableName(db *DB) string { s.defaultTableName = tabler.TableName() } else { tableName := ToTableName(s.ModelType.Name()) - if db == nil || !db.parent.singularTable { + if db == nil || (db.parent != nil && !db.parent.singularTable) { tableName = inflection.Plural(tableName) } s.defaultTableName = tableName