Преглед на файлове

Fix the wrong key about FindOne in mongo of goctl. (#2523)

wuleiming2009 преди 2 години
родител
ревизия
ea52fe2e0d
променени са 2 файла, в които са добавени 2 реда и са изтрити 2 реда
  1. 1 1
      tools/goctl/model/mongo/readme.md
  2. 1 1
      tools/goctl/model/mongo/template/model.tpl

+ 1 - 1
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:

+ 1 - 1
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: