Skip to content

Commit

Permalink
Merge pull request #115 from wxw9868/gormt
Browse files Browse the repository at this point in the history
修复bug
  • Loading branch information
xxjwxc authored Mar 5, 2021
2 parents a095bb9 + d1afbd5 commit a4c817f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions data/view/genfunc/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,20 @@ func (obj *_{{$obj.StructName}}Mgr) GetByOptions(opts ...Option) (results []*{{$
{{range $oem := $obj.Em}}
// GetFrom{{$oem.ColStructName}} 通过{{$oem.ColName}}获取内容 {{$oem.Notes}} {{if $oem.IsMulti}}
func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}} {{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColNameEx}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&results).Error
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&results).Error
{{GenPreloadList $obj.PreloadList true}}
return
}
{{else}}
func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}} {{$oem.Type}}) (result {{$obj.StructName}}, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColNameEx}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&result).Error
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&result).Error
{{GenPreloadList $obj.PreloadList false}}
return
}
{{end}}
// GetBatchFrom{{$oem.ColStructName}} 批量唯一主键查找 {{$oem.Notes}}
func (obj *_{{$obj.StructName}}Mgr) GetBatchFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}}s []{{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColNameEx}} IN (?)", {{CapLowercase $oem.ColStructName}}s).Find(&results).Error
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColName}} IN (?)", {{CapLowercase $oem.ColStructName}}s).Find(&results).Error
{{GenPreloadList $obj.PreloadList true}}
return
}
Expand Down
2 changes: 1 addition & 1 deletion data/view/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func GenFListIndex(info FList, status int) string {
{
var strs []string
for _, v := range info.Kem {
strs = append(strs, fmt.Sprintf("`%v` = ?", v.ColName))
strs = append(strs, fmt.Sprintf("%v = ?", v.ColName)) //wxw 2021.2.26 16:53
}
return strings.Join(strs, " AND ")
}
Expand Down
11 changes: 8 additions & 3 deletions data/view/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,15 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
pkg.AddImport(`"context"`) // 添加import信息
pkg.AddImport(cnf.EImportsHead["gorm.Model"])

data := funDef{
StructName: getCamelName(tab.Name),
TableName: tab.Name,
// wxw 2021.2.26 17:17
var data funDef
data.TableName = tab.Name
tablePrefix := config.GetTablePrefix()
//如果设置了表前缀
if tablePrefix != "" {
tab.Name = strings.TrimLeft(tab.Name, tablePrefix)
}
data.StructName = getCamelName(tab.Name)

var primary, unique, uniqueIndex, index []FList
for _, el := range tab.Em {
Expand Down

0 comments on commit a4c817f

Please sign in to comment.