From f4aa43544632181c095eb31bdae29ab0dd65339c Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 28 Oct 2013 15:49:05 +0800 Subject: [PATCH] Basic support for plurals --- model.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/model.go b/model.go index 7cf25d25..eac82355 100644 --- a/model.go +++ b/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 }