Skip to content

Commit

Permalink
feature: model Joins & Preload methods support multiple RelationField (
Browse files Browse the repository at this point in the history
…go-gorm#424)

* feat: modify preload function on template to support Preloading multiple relations

* feat: modify Joins function on template to support Joins multiple relations

* fix(tempale-method): use plural for Joins & Preload args
  • Loading branch information
alfarih31 authored Apr 20, 2022
1 parent 1ee2eaa commit 2c8e792
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions internal/template/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,18 @@ func ({{.S}} {{.NewStructName}}Do) Assign(attrs ...field.AssignExpr) *{{.NewStru
return {{.S}}.withDO({{.S}}.DO.Assign(attrs...))
}
func ({{.S}} {{.NewStructName}}Do) Joins(field field.RelationField) *{{.NewStructName}}Do {
return {{.S}}.withDO({{.S}}.DO.Joins(field))
}
func ({{.S}} {{.NewStructName}}Do) Preload(field field.RelationField) *{{.NewStructName}}Do {
return {{.S}}.withDO({{.S}}.DO.Preload(field))
func ({{.S}} {{.NewStructName}}Do) Joins(fields ...field.RelationField) *{{.NewStructName}}Do {
for _, _f := range fields {
{{.S}} = *{{.S}}.withDO({{.S}}.DO.Joins(_f))
}
return &{{.S}}
}
func ({{.S}} {{.NewStructName}}Do) Preload(fields ...field.RelationField) *{{.NewStructName}}Do {
for _, _f := range fields {
{{.S}} = *{{.S}}.withDO({{.S}}.DO.Preload(_f))
}
return &{{.S}}
}
func ({{.S}} {{.NewStructName}}Do) FirstOrInit() (*{{.StructInfo.Package}}.{{.StructInfo.Type}}, error) {
Expand Down

0 comments on commit 2c8e792

Please sign in to comment.