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:
Ariel Mashraki
2022-07-12 18:13:45 +03:00
committed by GitHub
parent b00e549c88
commit 6c8a1308ec
38 changed files with 4162 additions and 164 deletions

View File

@@ -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 }}

View File

@@ -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