From 05b3f036f8bbb96b22336bbe3510253879ac0ab1 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 1 Aug 2015 11:20:08 +0800 Subject: [PATCH] Change plural engine to github.com/qor/inflection --- model_struct.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/model_struct.go b/model_struct.go index 9c07db9b..72caec24 100644 --- a/model_struct.go +++ b/model_struct.go @@ -5,10 +5,11 @@ import ( "fmt" "go/ast" "reflect" - "regexp" "strconv" "strings" "time" + + "github.com/qor/inflection" ) var modelStructs = map[reflect.Type]*ModelStruct{} @@ -71,9 +72,6 @@ type Relationship struct { JoinTableHandler JoinTableHandlerInterface } -var pluralMapKeys = []*regexp.Regexp{regexp.MustCompile("ch$"), regexp.MustCompile("ss$"), regexp.MustCompile("sh$"), regexp.MustCompile("day$"), regexp.MustCompile("y$"), regexp.MustCompile("x$"), regexp.MustCompile("([^s])s?$")} -var pluralMapValues = []string{"ches", "sses", "shes", "days", "ies", "xes", "${1}s"} - func (scope *Scope) GetModelStruct() *ModelStruct { var modelStruct ModelStruct @@ -113,11 +111,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct { } else { name := ToDBName(scopeType.Name()) if scope.db == nil || !scope.db.parent.singularTable { - for index, reg := range pluralMapKeys { - if reg.MatchString(name) { - name = reg.ReplaceAllString(name, pluralMapValues[index]) - } - } + name = inflection.Plural(name) } modelStruct.defaultTableName = name