forked from mirror/gorm
Basic support for plurals
This commit is contained in:
parent
2388dacfe3
commit
f4aa435446
12
model.go
12
model.go
|
@ -120,8 +120,16 @@ func (m *Model) TableName() (str string, err error) {
|
|||
break
|
||||
}
|
||||
}
|
||||
reg, _ := regexp.Compile("s*$")
|
||||
str = reg.ReplaceAllString(toSnake(t.Name()), "s")
|
||||
|
||||
str = toSnake(t.Name())
|
||||
|
||||
pluralMap := map[string]string{"ch": "ches", "ss": "sses", "sh": "shes", "day": "days", "y": "ies", "x": "xes", "s?": "s"}
|
||||
for key, value := range pluralMap {
|
||||
reg := regexp.MustCompile(key + "$")
|
||||
if reg.MatchString(str) {
|
||||
return reg.ReplaceAllString(str, value), err
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue