mirror of https://github.com/go-gorm/gorm.git
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:
parent
a6382da485
commit
8316f94b72
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue