mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/sql/sqlgraph: support sql.Scanner types when scanning IDs (#1987)
Fixed https://github.com/ent/ent/issues/1985
This commit is contained in:
@@ -4,7 +4,7 @@ This source code is licensed under the Apache 2.0 license found
|
||||
in the LICENSE file in the root directory of this source tree.
|
||||
*/}}
|
||||
|
||||
{{/* gotype: entgo.io/ent/entc/gen.typeScope */}}
|
||||
{{/* gotype: entgo.io/ent/entc/gen.Type */}}
|
||||
|
||||
{{ define "dialect/sql/create" }}
|
||||
{{ $builder := pascal $.Scope.Builder }}
|
||||
@@ -19,9 +19,14 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
{{- if and $.ID.UserDefined (not $.ID.Type.Numeric) }}
|
||||
{{- if and $.ID.UserDefined (or $.ID.Type.ValueScanner (not $.ID.Type.Numeric)) }}
|
||||
if _spec.ID.Value != nil {
|
||||
_node.ID = _spec.ID.Value.({{ $.ID.Type }})
|
||||
{{- /* If the ID type is not a pointer, but implements the ValueScanner interface (e.g. UUID fields). */}}
|
||||
{{- if and $.ID.Type.ValueScanner (not $.ID.Type.RType.IsPtr) }}
|
||||
_node.ID = *_spec.ID.Value.(*{{ $.ID.Type }})
|
||||
{{- else }}
|
||||
_node.ID = _spec.ID.Value.({{ $.ID.Type }})
|
||||
{{- end }}
|
||||
}
|
||||
{{- else }}
|
||||
{{- if $.ID.UserDefined }}
|
||||
@@ -56,7 +61,7 @@ func ({{ $receiver }} *{{ $builder }}) createSpec() (*{{ $.Name }}, *sqlgraph.Cr
|
||||
{{- if $.ID.UserDefined }}
|
||||
if id, ok := {{ $mutation }}.{{ $.ID.MutationGet }}(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
_spec.ID.Value = {{ if and $.ID.Type.ValueScanner (not $.ID.Type.RType.IsPtr) }}&{{ end }}id
|
||||
}
|
||||
{{- end }}
|
||||
{{- range $f := $.MutationFields }}
|
||||
|
||||
Reference in New Issue
Block a user