From 6ad5ab2fa65692cef55364a3b9d394ba5664b503 Mon Sep 17 00:00:00 2001 From: Brent Hughes Date: Thu, 11 Oct 2018 15:47:52 -0500 Subject: [PATCH] Fix Panic in test scenerio 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 8c27e209..5152d804 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