entc/gen/template: allow mutating the sqlgraph.CreateSpec by ent extensions or user templates

This commit is contained in:
Ariel Mashraki
2021-01-19 09:34:40 +02:00
committed by Ariel Mashraki
parent aa73b9067f
commit 63eb68a269
3 changed files with 9 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -167,6 +167,7 @@ var (
partialPatterns = [...]string{
"dialect/additional/*",
"dialect/*/import/additional/*",
"dialect/*/*/spec/*",
}
// templates holds the Go templates for the code generation.
templates *Template

View File

@@ -43,6 +43,12 @@ func ({{ $receiver }} *{{ $builder }}) createSpec() (*{{ $.Name }}, *sqlgraph.Cr
},
}
)
{{- /* Allow mutating the sqlgraph.CreateSpec by ent extensions or user templates.*/}}
{{- with $tmpls := matchTemplate "dialect/sql/create/spec/*" }}
{{- range $tmpl := $tmpls }}
{{- xtemplate $tmpl $ }}
{{- end }}
{{- end }}
{{- if $.ID.UserDefined }}
if id, ok := {{ $mutation }}.{{ $.ID.MutationGet }}(); ok {
_node.ID = id