From 4aeb4551b4e3e91d87661d0a7ec7c98199be65ee Mon Sep 17 00:00:00 2001 From: wuleiming2009 <369972511@qq.com> Date: Mon, 17 Oct 2022 12:43:31 +0800 Subject: [PATCH 1/2] Update model.tpl to fix key in FindOne Update model.tpl to fix key in FindOne --- tools/goctl/model/mongo/template/model.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/goctl/model/mongo/template/model.tpl b/tools/goctl/model/mongo/template/model.tpl index c07d78969245..9265d13fdf18 100644 --- a/tools/goctl/model/mongo/template/model.tpl +++ b/tools/goctl/model/mongo/template/model.tpl @@ -47,7 +47,7 @@ func (m *default{{.Type}}Model) FindOne(ctx context.Context, id string) (*{{.Typ } var data {{.Type}} - {{if .Cache}}key := prefix{{.Type}}CacheKey + data.ID.Hex(){{end}} + {{if .Cache}}key := prefix{{.Type}}CacheKey + id{{end}} err = m.conn.FindOne(ctx, {{if .Cache}}key, {{end}}&data, bson.M{"_id": oid}) switch err { case nil: From dd4bf5168603f9fc85669217fb7f9d076bd46d15 Mon Sep 17 00:00:00 2001 From: wuleiming2009 <369972511@qq.com> Date: Mon, 17 Oct 2022 12:44:32 +0800 Subject: [PATCH 2/2] Update readme.md to fix key in FindOne Update readme.md to fix key in FindOne --- tools/goctl/model/mongo/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/goctl/model/mongo/readme.md b/tools/goctl/model/mongo/readme.md index e8ed8be8bb12..1c19cc933457 100644 --- a/tools/goctl/model/mongo/readme.md +++ b/tools/goctl/model/mongo/readme.md @@ -105,7 +105,7 @@ func (m *defaultUserModel) FindOne(ctx context.Context, id string) (*User, error } var data User - key := prefixUserCacheKey + data.ID.Hex() + key := prefixUserCacheKey + id err = m.conn.FindOne(ctx, key, &data, bson.M{"_id": oid}) switch err { case nil: