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.
This commit is contained in:
Brent Hughes 2018-10-11 15:47:52 -05:00 committed by GitHub
parent 742154be9a
commit 6ad5ab2fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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