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.
This commit is contained in:
Brent Hughes 2019-01-02 07:28:46 -06:00 committed by Jinzhu
parent a6382da485
commit 8316f94b72
1 changed files with 1 additions and 1 deletions

View File

@ -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