From 3cdd9ef36e442a9eb8c8fe84348c8bafff0797b4 Mon Sep 17 00:00:00 2001 From: CyJaySong <29367599+CyJaySong@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:22:02 +0800 Subject: [PATCH] cmd/gf: fix command `gf gen dao` for fieldMapping feature (#3549) --- cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go | 2 +- cmd/gf/internal/cmd/gendao/gendao_structure.go | 2 +- os/gfile/gfile_replace.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go b/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go index 9642ad36eed..5958e238e4a 100644 --- a/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go +++ b/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go @@ -241,7 +241,7 @@ func Test_Gen_Dao_FieldMapping(t *testing.T) { in = gendao.CGenDaoInput{ Path: path, Link: link, - Tables: "table_user", + Tables: "", TablesEx: "", Group: group, Prefix: "", diff --git a/cmd/gf/internal/cmd/gendao/gendao_structure.go b/cmd/gf/internal/cmd/gendao/gendao_structure.go index 4e457aff376..2fa4745ebf4 100644 --- a/cmd/gf/internal/cmd/gendao/gendao_structure.go +++ b/cmd/gf/internal/cmd/gendao/gendao_structure.go @@ -133,7 +133,7 @@ func generateStructFieldDefinition( } if in.FieldMapping != nil && len(in.FieldMapping) > 0 { - if typeMapping, ok := in.FieldMapping[fmt.Sprintf("%s.%s", in.Tables, newFiledName)]; ok { + if typeMapping, ok := in.FieldMapping[fmt.Sprintf("%s.%s", in.TableName, newFiledName)]; ok { localTypeNameStr = typeMapping.Type appendImport = typeMapping.Import } diff --git a/os/gfile/gfile_replace.go b/os/gfile/gfile_replace.go index 3cb7b689fac..74fba01d6ff 100644 --- a/os/gfile/gfile_replace.go +++ b/os/gfile/gfile_replace.go @@ -19,7 +19,7 @@ func ReplaceFile(search, replace, path string) error { func ReplaceFileFunc(f func(path, content string) string, path string) error { data := GetContents(path) result := f(path, data) - if len(data) != len(result) && data != result { + if len(data) != len(result) || data != result { return PutContents(path, result) } return nil