mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
entc/gen: edge schema with custom ids (#2742)
Fixed https://github.com/ent/ent/issues/2740 Fixed https://github.com/ent/ent/issues/2741
This commit is contained in:
@@ -31,10 +31,12 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: {{ $n.Package }}.Table,
|
||||
Columns: {{ $n.Package }}.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.{{ $n.ID.Type.ConstName }},
|
||||
Column: {{ $n.Package }}.{{ $n.ID.Constant }},
|
||||
},
|
||||
{{- if $n.HasOneFieldID }}
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.{{ $n.ID.Type.ConstName }},
|
||||
Column: {{ $n.Package }}.{{ $n.ID.Constant }},
|
||||
},
|
||||
{{- end }}
|
||||
},
|
||||
Type: "{{ $n.Name }}",
|
||||
Fields: map[string]*sqlgraph.FieldSpec{
|
||||
@@ -110,16 +112,18 @@ type predicateAdder interface {
|
||||
})
|
||||
}
|
||||
|
||||
{{ $type := $n.ID.Type.Type.String }}
|
||||
{{ $iface := print (pascal $type) "P" }}
|
||||
{{- if $n.ID.IsTime }}{{ $iface = "TimeP" }}
|
||||
{{- else if or $n.ID.IsBytes $n.ID.IsJSON }}{{ $iface = "BytesP" }}
|
||||
{{- else if $n.ID.IsUUID }}{{ $iface = "ValueP" }}
|
||||
{{- if $n.HasOneFieldID }}
|
||||
{{ $type := $n.ID.Type.Type.String }}
|
||||
{{ $iface := print (pascal $type) "P" }}
|
||||
{{- if $n.ID.IsTime }}{{ $iface = "TimeP" }}
|
||||
{{- else if or $n.ID.IsBytes $n.ID.IsJSON }}{{ $iface = "BytesP" }}
|
||||
{{- else if $n.ID.IsUUID }}{{ $iface = "ValueP" }}
|
||||
{{- end }}
|
||||
// WhereID applies the entql {{ $type }} predicate on the id field.
|
||||
func (f *{{ $filter }}) WhereID(p entql.{{ $iface }}) {
|
||||
f.Where(p.Field({{ $n.Package }}.{{ $n.ID.Constant }}))
|
||||
}
|
||||
{{- end }}
|
||||
// WhereID applies the entql {{ $type }} predicate on the id field.
|
||||
func (f *{{ $filter }}) WhereID(p entql.{{ $iface }}) {
|
||||
f.Where(p.Field({{ $n.Package }}.{{ $n.ID.Constant }}))
|
||||
}
|
||||
|
||||
{{ range $f := $n.Fields }}
|
||||
{{ $type := $f.Type.Type.String }}
|
||||
|
||||
@@ -335,7 +335,7 @@ func (u *{{ $upsertBulk }}) UpdateNewValues() *{{ $upsertBulk }} {
|
||||
{{- if or $udfID $.ImmutableFields }}
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
{{- if $.ID.UserDefined }}
|
||||
{{- if $udfID }}
|
||||
if _, exists := b.mutation.ID(); exists {
|
||||
s.SetIgnore({{ $.Package }}.{{ $.ID.Constant }})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user