mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/edge: add annotation support for edges (#651)
This commit is contained in:
@@ -10,4 +10,5 @@ package ent
|
||||
type CardExtension struct {
|
||||
Number string
|
||||
Name string
|
||||
Spec int
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -10,4 +10,5 @@ package ent
|
||||
type CardExtension struct {
|
||||
Number string
|
||||
Name string
|
||||
Spec int
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user