schema/edge: add annotation support for edges (#651)

This commit is contained in:
Ariel Mashraki
2020-08-01 15:38:47 +03:00
committed by GitHub
parent e9b406ca65
commit 05dfd6b78b
11 changed files with 136 additions and 71 deletions

View File

@@ -10,4 +10,5 @@ package ent
type CardExtension struct {
Number string
Name string
Spec int
}

View File

@@ -50,6 +50,9 @@ func (Card) Edges() []ent.Edge {
Ref("card").
Unique(),
edge.From("spec", Spec.Type).
Ref("card"),
Ref("card").
Annotations(&template.Extension{
Type: "int",
}),
}
}

View File

@@ -11,6 +11,7 @@ in the LICENSE file in the root directory of this source tree.
{{ range $n := $.Nodes }}
{{ $hasExt := false }}
{{ range $f := $n.Fields }}{{ if $f.Annotations.Extension }}{{ $hasExt = true }}{{ end }}{{ end }}
{{ range $e := $n.Edges }}{{ if $e.Annotations.Extension }}{{ $hasExt = true }}{{ end }}{{ end }}
{{/* If one or fields contain the "Extension" annotation */}}
{{ if $hasExt }}
// {{ $n.Name }}Extension is a type for holding the extension information defined in the schema.
@@ -20,6 +21,11 @@ in the LICENSE file in the root directory of this source tree.
{{ $f.StructField }} {{ $ant.Type }}
{{- end }}
{{- end }}
{{- range $e := $n.Edges }}
{{- with $ant := $e.Annotations.Extension }}
{{ $e.StructField }} {{ $ant.Type }}
{{- end }}
{{- end }}
}
{{ end }}
{{ end }}

View File

@@ -10,4 +10,5 @@ package ent
type CardExtension struct {
Number string
Name string
Spec int
}