From 7d4a548d29f5ad1702dabeacae7673134d0cd2ae Mon Sep 17 00:00:00 2001 From: Keson Date: Mon, 12 Oct 2020 14:34:11 +0800 Subject: [PATCH] fix: template cache key (#121) --- tools/goctl/model/sql/gen/findonebyfield.go | 2 +- tools/goctl/model/sql/template/find.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/goctl/model/sql/gen/findonebyfield.go b/tools/goctl/model/sql/gen/findonebyfield.go index d2b67ae0..8bd1d7ba 100644 --- a/tools/goctl/model/sql/gen/findonebyfield.go +++ b/tools/goctl/model/sql/gen/findonebyfield.go @@ -25,7 +25,6 @@ func genFindOneByField(table Table, withCache bool) (string, string, error) { "withCache": withCache, "cacheKey": table.CacheKey[field.Name.Source()].KeyExpression, "cacheKeyVariable": table.CacheKey[field.Name.Source()].Variable, - "primaryKeyLeft": table.CacheKey[table.PrimaryKey.Name.Source()].Left, "lowerStartCamelObject": stringx.From(camelTableName).UnTitle(), "lowerStartCamelField": stringx.From(camelFieldName).UnTitle(), "upperStartCamelPrimaryKey": table.PrimaryKey.Name.ToCamel(), @@ -39,6 +38,7 @@ func genFindOneByField(table Table, withCache bool) (string, string, error) { if withCache { out, err := util.With("findOneByFieldExtraMethod").Parse(template.FindOneByFieldExtraMethod).Execute(map[string]interface{}{ "upperStartCamelObject": camelTableName, + "primaryKeyLeft": table.CacheKey[table.PrimaryKey.Name.Source()].Left, "lowerStartCamelObject": stringx.From(camelTableName).UnTitle(), "originalPrimaryField": table.PrimaryKey.Name.Source(), }) diff --git a/tools/goctl/model/sql/template/find.go b/tools/goctl/model/sql/template/find.go index e24948c0..ee1d87c8 100644 --- a/tools/goctl/model/sql/template/find.go +++ b/tools/goctl/model/sql/template/find.go @@ -65,7 +65,7 @@ func (m *{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}({{.in}}) (*{{ ` var FindOneByFieldExtraMethod = ` func (m *{{.upperStartCamelObject}}Model) formatPrimary(primary interface{}) string { - return fmt.Sprintf("%s%v", cacheUserIdPrefix, primary) + return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary) } func (m *{{.upperStartCamelObject}}Model) queryPrimary(conn sqlx.SqlConn, v, primary interface{}) error {