Basic support for plurals

This commit is contained in:
Jinzhu 2013-10-28 15:49:05 +08:00
parent 2388dacfe3
commit f4aa435446
1 changed files with 10 additions and 2 deletions

View File

@ -120,8 +120,16 @@ func (m *Model) TableName() (str string, err error) {
break 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 return
} }